cmake target_link_libraries() 启动错误 Cannot specify link libraries for target "debug"

cmake target_link_libraries() launching error Cannot specify link libraries for target "debug"

我正在尝试 link 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

但它并没有改变任何东西。它开始得更早,我注意到我把我的 "add_executable" 放在 target_link_libraries 命令之后,然后更改了它,错误并没有得到任何改善。

我没有放置任何标志(如 -lsfml-graphics 等),因为我现在不构建(我不能,更准确地说。) set_CMAKE_RUNTIME_OUTPUT_DIRECTORY 是为了强制在项目的 bin 文件夹中输出,而不是在 Clion 目录中。

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 ... )

第一个参数被视为目标名称,因此您会看到错误

Error:Cannot specify link libraries for target "debug" which is not built by this project