我的cmake配置中存在依赖性问题。
当我从项目的根目录开始构建时,它总是会出错。当我在add_subdirectory(application)
处禁用LibCalcBin
时,它会成功构建library
。然后,我可以构建application
。
为什么cmake不按照我在add_subdirectory命令中指定的顺序构建library
然后application
。有什么方法可以解决这个问题吗?谢谢。
Please set them or make sure they are set and tested correctly in the CMake files:
LibCalcBin
linked by target "run" in directory ...
cmake_minimum_required(VERSION 3.3)
project(DLLAbstract)
# specify where to put executable
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# specify where to put binaries
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# compile and build library
add_subdirectory(library)
# compile and build application
add_subdirectory(application)
set(src LibCalc.cpp Calculator.cpp)
add_definitions(-DDLL_EXPORT)
add_library(LibCalc SHARED ${src})
set(Src main.cpp)
find_path(LibCalcHeader
NAMES
LibCalc.hpp
PATHS
${PROJECT_SOURCE_DIR}/library
)
find_library(LibCalcBin
NAMES
LibCalc
PATHS
${PROJECT_SOURCE_DIR}/bin/Debug
${PROJECT_SOURCE_DIR}/bin/Release
${PROJECT_SOURCE_DIR}/bin
)
include_directories(${LibCalcHeader})
add_executable(run ${Src})
target_link_libraries(run ${LibCalcBin})
答案 0 :(得分:1)
find_library
命令用于查找不属于项目的库。对于由add_library
命令创建的库,不需要特殊处理,您可以在target_link_libraries
调用中使用目标名称:
target_link_libraries(run LibCalc)