我正在尝试链接CLion和SFML(使用windows,mingw w64,SFML 64,CMake) 我试图正确配置CMakeLists.txt。
这是cmakelist:
cmake_minimum_required(VERSION 3.2)
project(Test_Utilisation_SFML)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
message(WARNING "CMake runtime output Directory : ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
add_executable(Test_Utilisation_SFML.exe ${SOURCE_FILES})
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
message (WARNING "lib dir : ${SFML_INCLUDE_DIR}")
message (WARNING "libs : ${SFML_LIBRARIES}")
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
message(WARNING "Line that does not appear because it fails the previous line")
endif()
这是CMake的输出:
Error:Cannot specify link libraries for target "debug" which is not built by this project.
Warning:CMake runtime output Directory : D:/JetBrains/workspace/c++/Test Utilisation SFML/bin
Warning:lib dir : C:/lib/SFML/SFML-2.3/include
Warning:libs : debug;C:/lib/SFML/SFML-2.3/lib/libsfml-system-d.a;optimized;C:/lib/SFML/SFML-2.3/lib/libsfml-system.a;debug;C:/lib/SFML/SFML-2.3/lib/libsfml-window-d.a;optimized;C:/lib/SFML/SFML-2.3/lib/libsfml-window.a;debug;C:/lib/SFML/SFML-2.3/lib/libsfml-graphics-d.a;optimized;C:/lib/SFML/SFML-2.3/lib/libsfml-graphics.a;debug;C:/lib/SFML/SFML-2.3/lib/libsfml-network-d.a;optimized;C:/lib/SFML/SFML-2.3/lib/libsfml-network.a;debug;C:/lib/SFML/SFML-2.3/lib/libsfml-audio-d.a;optimized;C:/lib/SFML/SFML-2.3/lib/libsfml-audio.a
我很遗憾地发现仅将“debug”视为目标是奇怪的,我更改了findSFML.cmake文件以使其成为
debug C:/lib/SFML/SFML-2.3/lib/libsfml-system-d.a
但它没有改变任何东西。它开始于早期,我注意到我在target_link_libraries命令之后添加了我的“add_executable”然后更改了它,错误没有变得更好。
我没有放任何标志(如-lsfml-graphics等),因为我现在不打造(我不能,更准确地说。) set_CMAKE_RUNTIME_OUTPUT_DIRECTORY用于强制输出项目的bin文件夹,而不是Clion目录。
答案 0 :(得分:2)
EXECUTABLE_NAME
未在target_link_libraries命令中设置,因此在调试版本中
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
扩展为
target_link_libraries(debug path/to/debug/library optimized path/to/release/library ... )
第一个参数被视为目标名称,因此您会看到错误
错误:无法为目标“debug”指定链接库,而不是 由这个项目建造