0

I am trying to link SFML to a C++ project using CMake. This setup works fine on my Linux machine but when I try to build on my mac, it can't find the library: ld: library not found for -lsfml-network. My install for SFML is the exact same (in the way I did it) on both machines.

My CMakeLists.txt linking looks as follows:

target_link_libraries( Playground ${OpenCV_LIBS} sfml-network sfml-window sfml-graphics sfml-system )

3
  • Can you make it work without cmake? Then you can at least rule out influence of that and reduce your question accordingly. This follows the rule of extracting an MCVE, which you should know from the guidelines for good questions. Commented Mar 9, 2018 at 19:54
  • Hmm, hadn't tried that. It works through normal linking but not through CMake, why is that? Commented Mar 9, 2018 at 19:58
  • Run make VERBOSE=1 after cmake to see exactly what flags cmake is giving the compiler. That can make it easier to diagnose the problem Commented Mar 9, 2018 at 20:06

1 Answer 1

1

SFML has a tutorial on how to compile using CMake. It provides a FindSFML.cmake file, so you can simply use find_package and target_link_libraries:

find_package(SFML REQUIRED COMPONENTS network window graphics system)
# ...

target_link_libraries(Playground
  ${SFML_LIBRARIES}

# If SFML did it correctly, this shouldn't be needed, but I can't tell from the
# documentation if they did:
  ${SFML_DEPENDENCIES}
)
Sign up to request clarification or add additional context in comments.

2 Comments

The FindSFML.cmake file has recently been removed (though it can be found in previous versions of the source repo) while the tutorial at this time does not appear to have been updated. It looks like some structural changes to the CMake system were made very recently and I hope to find updated documentation on it soon.
Update: FindSFML.cmake has been replaced by SFMLConfig.cmake as explained in this pull request. The usage is similar and slightly simpler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.