It is now HOURS, that I tried to solve this issue: "fatal error: SFML/Graphics.hpp: No such file or directory"
I am using Visual Studio Code under Windows 11.
I followed the tutorial and I have created the following CMakeLists.txt file
make_minimum_required
(VERSION 3.23
)project(MySFMLFirstProject LANGUAGES CXX
)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin
)include(FetchContent
)FetchContent_Declare
(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x
)FetchContent_MakeAvailable
(SFML
)add_executable(MySFMLFirstProject
)target_sources
(MySFMLFirstProject PRIVATE
"src/main.cpp" "src/plots.cpp")target_include_directories
(MySFMLFirstProject PRIVATE
"${PROJECT_SOURCE_SIR}" )add_subdirectory("sfml-widgets/src/Gui")add_subdirectory("sfml-widgets/src/Gui/Layouts")add_subdirectory("sfml-widgets/src/Gui/Utils")target_link_libraries(MySFMLFirstProject PRIVATE sfml-graphics ws2_32 wlanapi
)target_compile_features
(MySFMLFirstProject PRIVATE cxx_std_17
)if(WIN32
) add_custom_command( TARGET MySFMLFirstProject
COMMENT "Copy OpenAL DLL" PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy
${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<
EQUAL:
${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:MySFMLFirstProject>
VERBATIM)endif()install(TARGETS MySFMLFirstProject
) This file is in the following directory C:\Users\Fabrice\Documents\C\firstSFML\my_sfml.
This directory also contains :
- the "src" directory which contains the 2x source files of my software
- the "sfml-widgets" directory coming from MIT
- the "build" directory, which is automatically generated when building the proiect; I guess this is thanks to the
FetchContent_Declare(SFML... command in the Cmakelist.txt file
In the main.cpp file (entry point of the software), there is a fatal error on the line
#include <SFML/Graphics.hpp>
BTW, if I remove this line from main.cpp, then the error appears when the build tries to compile some cpp files of the "sfml-widgets" which also have the same line #include <SFML/Graphics.hpp>
I don' t know what to do!
I tried to directly include the path to the file as #include "build/..../Graphics.hpp" in the main.cpp, but then, as I said, the problem appears when building some modules of the "sfm-widgets" library.
I tried to include the path to the Graphics.hpp into the Cmakelist.txt, but it didn't work, and I guess this is not a clean way of working.
I tried to copy the whole content of the sfml-src directory from the generated build directory as a new directory at the same level as "sfml-widgets" directory. It didn't work, and, again, it doesn' t seem to be a clean way of working.
Could you please help me a I am very frustated ?
Fabrice