gpt4 book ai didi

cmake - 如何使用 CMake 修改导入库的范围

转载 作者:行者123 更新时间:2023-12-02 02:17:54 26 4
gpt4 key购买 nike

CMake 问题,

导入的库在其创建目录及以下目录中具有作用域。

如果我想在父范围内使用这个库,我应该怎么做?

例如,

顶部 CMakeLists.txt

add_subdirectory(sub)
add_executable(myapp main.cpp)
target_link_libraries(myapp imported_lib)

子CMakeLists.txt

add_library(imported_lib STATIC IMPORTED)

谢谢你的帮助~~

最佳答案

与经典库不同,导入的库仅限于目录。这可以使用 GLOBAL 选项进行更改。

这是一个 extract from the documentation :

The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility.

例子:

add_library(imported_lib STATIC IMPORTED GLOBAL)

据我所知,此选项一直可用。

关于cmake - 如何使用 CMake 修改导入库的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9628350/

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