Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: fatal error: SFML/Graphics.hpp: No such file or directory : SOLVED !  (Read 2574 times)

0 Members and 1 Guest are viewing this topic.

fb

  • Newbie
  • *
  • Posts: 2
    • View Profile
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


« Last Edit: December 05, 2023, 11:26:04 am by eXpl0it3r »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: fatal error: SFML/Graphics.hpp: No such file or directory
« Reply #1 on: December 04, 2023, 07:41:28 pm »
Hi!

It doesn't look like you're including SFML's "include" folder.
In this folder should be an "SFML" folder that contains "Graphics.hpp" (as well as the others).
It should look a bit like this one:
https://github.com/SFML/SFML/tree/master/include

Note that the include folder should be included so that the SFML part can be added when using #include. e.g. #include <SFML/Graphics.hpp>
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

fb

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: fatal error: SFML/Graphics.hpp: No such file or directory
« Reply #2 on: December 04, 2023, 09:57:27 pm »
Hi !

Many thanks for your help !

I had to do the following:
  - include the following line into the CMakeLists.txt file:
add_subdirectory("build/_deps/sfml-src/include/SFML")

  - include the following line into the main.cpp and plots.cpp files:
#include "build/_deps/sfml-src/include/SFML/Graphics.hpp"

  - create a new CMakeLists.txt in the build\_deps\sfml-src\include\SFML subdirectory, this file containing:
target_sources(MySFMLFirstProject PRIVATE
   Graphics.hpp
)


I wouldn' t have guessed this in the first place !
The last point was found thanks to a new error message appearing during CMake configuration asking for a CMakeLists.txt file into this subdirectory, which I created successfully by looking at other examples of CMakeLists.txt files.

Many thanks again !

Thrasher

  • SFML Team
  • Jr. Member
  • *****
  • Posts: 57
    • View Profile
Re: fatal error: SFML/Graphics.hpp: No such file or directory : SOLVED !
« Reply #3 on: December 04, 2023, 10:36:25 pm »
Linking to the `sfml-graphics` target should also result in the correct include directories being specified.

Your C++ and CMake code should not include build/_deps paths. That's unnecessary and a sign that some problem still exists elsewhere.

In this past I've seen this problem caused by someone having unnecessary files laying around. They had some sfml-graphics prebuilt library lying around from previous failed attempts to use SFML. Once they deleted that file then CMake started working again. In general don't have stale files laying around since they're prone to break things simply by existing.
« Last Edit: December 04, 2023, 10:41:56 pm by Thrasher »

 

anything