Jonah Mevert
Jonah Mevert

Reputation: 43

SFML headers not found when compiling using CMake and GCC (MacOS Sierra)

I have been trying to use SFML in a CMake project, specifically the header SFML/Audio.hpp. I installed SMFL using Homebrew, and both the .dylib-files and the headers should be located correctly, in /usr/local/lib and /usr/local/include, respectively.

Now running CMake works fine, telling me that it has Found SFML 2.4.2 in /usr/local/include.

However, when compiling the project (using make), I get the following error:

/path/to/project.hpp:12:10: fatal error: 'SFML/Audio.hpp' file not found.

Does anyone know why this is happening?

Note: Compiling works fine for colleagues of mine using the same CMake- and source files on various Linux operating systems.

Upvotes: 0

Views: 693

Answers (1)

Mario
Mario

Reputation: 36537

This sounds like you simply forgot to add SFML's include directory. On Linux, they probably install SFML to some system path where GCC (or Clang) look by default, so they don't need any additional CMake directives.

Luckily, fixing this is pretty simple.

Add the following line to your CMakeLists.txt somewhere before defining targets:

include_directories(${SFML_INCLUDE_DIR})

The variable SFML_INCLUDE_DIR is populated when you successfully call find_package(SFML...).

While you're at it, you might also want to ensure to link to the proper library files in the correct order:

target_link_libraries(myTargetName ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

Again, both variables are populated automatically.

Upvotes: 0

Related Questions