cmake add_subdirectory 命令的执行顺序
cmake order of execution of add_subdirectory command
我的 cmake 配置中存在依赖性问题。
当我从项目的根目录开始构建时,它总是报错。当我在使用 LibCalcBin
的地方禁用 add_subdirectory(application)
时,它会成功构建 library
。然后,我可以构建 application
。
为什么 cmake 不先构建 library
然后再构建 application
,正如我在 add_subdirectory 命令的顺序中指定的那样。有什么办法可以解决这个问题吗?谢谢。
错误
Please set them or make sure they are set and tested correctly in the CMake files:
LibCalcBin
linked by target "run" in directory ...
./CMakeList.txt(根目录)
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})
find_library
命令用于查找不属于您的项目的库。对于由 add_library
命令创建的库,不需要特殊处理,您可以在 target_link_libraries
调用中使用目标名称:
target_link_libraries(run LibCalc)
我的 cmake 配置中存在依赖性问题。
当我从项目的根目录开始构建时,它总是报错。当我在使用 LibCalcBin
的地方禁用 add_subdirectory(application)
时,它会成功构建 library
。然后,我可以构建 application
。
为什么 cmake 不先构建 library
然后再构建 application
,正如我在 add_subdirectory 命令的顺序中指定的那样。有什么办法可以解决这个问题吗?谢谢。
错误
Please set them or make sure they are set and tested correctly in the CMake files:
LibCalcBin
linked by target "run" in directory ...
./CMakeList.txt(根目录)
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})
find_library
命令用于查找不属于您的项目的库。对于由 add_library
命令创建的库,不需要特殊处理,您可以在 target_link_libraries
调用中使用目标名称:
target_link_libraries(run LibCalc)