gpt4 book ai didi

CMakeLists.txt 中的 CMake 错误(target_link_libraries)

转载 作者:行者123 更新时间:2023-12-04 17:22:37 27 4
gpt4 key购买 nike

我对 CMake 有问题。我写了一个 CMakeList.txt 文件。但是当我用 Cmake 运行它时,我得到了一个奇怪的错误“CMakeLists.txt:17 (target_link_libraries) 上的 CMake 错误:
无法为不是由此构建的目标“调试”指定链接库
项目。”。

是否可以创建一个可以同时为 Debug 和 Release 模式构建项目文件的 Cmake 文件?或者有没有简单的方法来解决这个错误?

我的 CMakeLists.txt 看起来像这样:

  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)

编辑:添加了新的源代码。

最佳答案

看起来您的 CMakeLists.txt 不包含两行中的任何一行(这取决于您要创建库还是可执行文件)

add_library(debug <files Name>)

或者
add_executable(debug <files Name>)

如果您的文件中有这些行,请将其放在 target_link_libraries () 之前

关于CMakeLists.txt 中的 CMake 错误(target_link_libraries),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18651178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com