问题
I am making a project using SFML and CMake. To do that, I followed the guide from SFML's GitHub.
I am adding the following lines to my CMakeLists.txt:
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED network audio graphics window system)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else()
message("SFML WAS NOT FOUND")
endif()
These lines are mostly just copied from the guide I mentioned. On ArchLinux, after installing SFML from the repositories, this works perfectly, and the generated MakeFile produces an executable
On Windows, after setting SFML_ROOT environment variable to my SFML location, CMake runs successfully, finding SFML and producing the following output:
Found SFML 2.4.2 in F:/Dev/CPPLibs/SFML-2.4.2/include
However, trying to build using the generated MakeFile results in a linker error:
...
C:\Users\complover116\Documents\CVMControl\src\cl_game.cc:14: error: undefined reference to `_imp___ZN2sf12RenderTarget7setViewERKNS_4ViewE'
C:\Users\complover116\Documents\CVMControl\src\cl_game.cc:15: error: undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
C:\Users\complover116\Documents\CVMControl\src\cl_game.cc:15: error: undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
... etc
Also, adding a debug command to CMakeLists.txt
message(${SFML_LIBRARIES})
Outputs this:
debugF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-network-d.aoptimizedF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-network.adebugF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-audio-d.aoptimizedF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-audio.adebugF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-graphics-d.aoptimizedF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-graphics.adebugF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-window-d.aoptimizedF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-window.adebugF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-system-d.aoptimizedF:/Dev/CPPLibs/SFML-2.4.2/lib/libsfml-system.a
It is concatenated like this, I did not copy it incorrectly
What am I doing wrong?
来源:https://stackoverflow.com/questions/46895227/cmakesfml-linker-error-even-though-library-is-specified-in-cmakelists-txt