CMake error in CMakeLists.txt (target_link_libraries)

I have a problem with CMake. I wrote a CMakeList.txt file. But when I run it with Cmake, I got the strange error "CMake error in CMakeLists.txt: 17 (target_link_libraries): Unable to specify link libraries for target" debugging "that is not built by this project .."

Is it possible to create a Cmake file that can simultaneously create a project file for Debug and Release mode? Or is there an easy way to fix this error?

My CMakeLists.txt looks like this:

cmake_minimum_required (VERSION 2.8) project (SimuVille) # Import required CMake files set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") file(GLOB_RECURSE files "*.cpp" ) add_executable(debug ${files}) # Find the find Modules 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}) target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES}) endif() #Find SfeMovie find_package(sfeMovie REQUIRED) if(SFEMOVIE_FOUND) include_directories(${SFEMOVIE_INCLUDE_DIR}) target_link_libraries(${EXECUTABLE_NAME} ${SFEMOVIE_LIBRARY}) endif() #Find Assimp find_package(ASSIMP REQUIRED) if(ASSIMP_FOUND) include_directories(${ASSIMP_INCLUDE_DIR}) target_link_libraries(${EXECUTABLE_NAME} ${ASSIMP_LIBRARY}) endif() #Find DevIL find_package(DevIL REQUIRED) if(IL_FOUND) include_directories(${IL_INCLUDE_DIR}) target_link_libraries(${EXECUTABLE_NAME} ${IL_LIBRARY}) target_link_libraries(${EXECUTABLE_NAME} ${ILU_LIBRARY}) target_link_libraries(${EXECUTABLE_NAME} ${ILUT_LIBRARY}) endif() #Find opengl libs find_package(OpenGL REQUIRED) include_directories(${OpenGL_INCLUDE_DIRS}) link_directories(${OpenGL_LIBRARY_DIRS}) add_definitions(${OpenGL_DEFINITIONS}) if(NOT OPENGL_FOUND) message(ERROR " OPENGL not found!") endif(NOT OPENGL_FOUND) #file(GLOB_RECURSE hfiles # "*.h" #) #add_executable(SimuVille ${hfiles}) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/Game) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/SfmlObject) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Camera) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/OpenglObject) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Playable) 

Edit: Added new source code.

+4
source share
1 answer

It looks like your CMakeLists.txt does not contain any of the two lines (which depends on whether you are creating a library or an executable file)

 add_library(debug <files Name>) 

OR

 add_executable(debug <files Name>) 

If you have these lines in your file, put it in front of target_link_libraries ()

+9
source

Source: https://habr.com/ru/post/1500862/


All Articles