Pierre-Antoine Guillaume
Pierre-Antoine Guillaume

Reputation: 1126

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

I'm trying to link CLion and SFML (using windows, mingw w64, SFML 64, CMake) and i triied to configure the CMakeLists.txt properly.

here's the 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()

and here's the output of 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

I honnestly found it weird to see only "debug" as a target, i changed the findSFML.cmake file to make it

debug C:/lib/SFML/SFML-2.3/lib/libsfml-system-d.a

but it didn't change anything. it began earlier, i noticed i put my "add_executable" after the target_link_libraries command then changed that, the error didn't get any better.

I didn't put any flag (like -lsfml-graphics etc) as i don't build for now (i can't, more precisely.) the set_CMAKE_RUNTIME_OUTPUT_DIRECTORY is here to force the output in the bin folder of the project, instead of in the Clion directory.

Upvotes: 2

Views: 5127

Answers (1)

Peter Petrik
Peter Petrik

Reputation: 10185

EXECUTABLE_NAME is not set in target_link_libraries command, so in a debug build

target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})

is expanded to

target_link_libraries(debug path/to/debug/library optimized path/to/release/library ... )

The first argument is treated as target name so you see the error

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

Upvotes: 2

Related Questions