gpt4 book ai didi

c++ - CMake 安装(子目录中的目标)

转载 作者:IT老高 更新时间:2023-10-28 22:04:07 33 4
gpt4 key购买 nike

考虑以下 CMakeLists.txt 文件:

add_subdirectory(execA)
add_subdirectory(libB)

install(TARGETS execA libB
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

我收到以下错误:

install TARGETS given target "execA" which does not exist in this
directory

execAlibB 有自己的 CMakeList.txt 文件,也位于 project 目录下作为构建目录,我正在运行 cmake (cmake ..):

project
|------ CMakeList.txt (the one with the code)
|----execA
| \- .cpp, .hpp and CMakelist.txt
|----libB
| \- .cpp, .hpp and CMakelist.txt
|---- lib
|---- bin
\---- build (where I´m commanding: $ cmake ..

如何解决这个错误?

最佳答案

根据this bugreport , install(TARGETS) 命令流只接受在同一目录中创建的目标

因此,您需要将 add_library() 调用移动到顶级目录,或者将 install(TARGETS) 调用拆分为每个目标的调用,然后移动每个将它们放入相应的子目录中。

自 CMake 3.13 install(TARGETS) can work即使是在其他目录中创建的目标。

install(TARGETS) can install targets that were created in other directories. When using such cross-directory install rules, running make install (or similar) from a subdirectory will not guarantee that targets from other directories are up-to-date.

关于c++ - CMake 安装(子目录中的目标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34443128/

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