2
votes

I've installed SFML but Visual Studio Code can't find the library. I am really new to Ubuntu and also pretty new to C++.

How can I get my IDE to recognize the library?

Here is what "libsfml-graphics-d.so" displays when entered into the terminal.

libsfml-window-d.so.2.5 (libc6,x86-64) => /usr/local/lib/libsfml-window-d.so.2.5  
libsfml-window-d.so (libc6,x86-64) => /usr/local/lib/libsfml-window-d.so  
libsfml-system-d.so.2.5 (libc6,x86-64) => /usr/local/lib/libsfml-system-d.so.2.5  
libsfml-system-d.so (libc6,x86-64) => /usr/local/lib/libsfml-system-d.so  
libsfml-network-d.so.2.5 (libc6,x86-64) => /usr/local/lib/libsfml-network-d.so.2.5    
libsfml-network-d.so (libc6,x86-64) => /usr/local/lib/libsfml-network-d.so
libsfml-graphics-d.so.2.5 (libc6,x86-64) => /usr/local/lib/libsfml-graphics-d.so.2.5    
libsfml-graphics-d.so (libc6,x86-64) => /usr/local/lib/libsfml-graphics-d.so  
libsfml-audio-d.so.2.5 (libc6,x86-64) => /usr/local/lib/libsfml-audio-d.so.2.5  
libsfml-audio-d.so (libc6,x86-64) => /usr/local/lib/libsfml-audio-d.so  

These are my User Settings in Visual Studio Code:

{  
    "editor.detectIndentation": false,  
    "editor.tabSize": 3,  
    "editor.insertSpaces": true,  
    "telemetry.enableTelemetry": false,  
    "telemetry.enableCrashReporter": false,  
   "window.zoomLevel": 1,  
    "editor.rulers": [80,120],  
   "clang.cxxflags": ["/usr/local/lib/"],  
}

When my mouse hovers over my C++ code, "#include <libsfml-graphics-d.so>" this text is displayed:

#include errors detected. Please update your includePath.
IntelliSense features for this translation unit (/home/userName/Desktop/Temp_Towers_Of_Babel/World_Generation/Main.cpp) will be provided by the Tag Parser.
Cannot open source file "libsfml-graphics-d.so"
'libsfml-graphics-d.so' file not found

1

1 Answers

1
votes

If you would like to include e.g SFML graphics why don't you try this way?

#include <SFML/Graphics.hpp>

On the other hand, I recommend you to install "c/c++" plugin if you would like to work with C++ in VS Code. You can find it on the marketplace with this search term c/c++. vscode-cpptools

If you can compile the example code from here with g++ that is a good point.

I think CMake also help me a lot in connection with proper configuration.

e.g. This is a simple CMakeLists.txt file. Here you can read the whole article.

cmake_minimum_required(VERSION 3.1)

project(SFMLTest)

## If you want to link SFML statically
# set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
# set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest main.cpp)
target_link_libraries(SFMLTest sfml-graphics sfml-audio)

whereis SFML command may help you to find the <sfml root prefix> part of this line # set(SFML_DIR "<sfml root prefix>/lib/cmake/SFML")

So my solution proposal step by step:

  1. Install VS Code c/c++ and CMake Tools plugins
  2. Check you can compile the example main.cpp with g++ from here
  3. Add the code snipet to a CMakeList.txt file in the project root folder
  4. Install cmake with apt install cmake command
  5. Go to your project folder and add a build folder with mkdir build
  6. cd build
  7. cmake ..
  8. make after this step you will get an executable named SFMLTest
  9. Open the project folder in VS Code. I think it will configure everything by itself
  10. If it is still not working, you should check this answer and try to configure the include path by yourself