CMake 找不到 IMPORTED 库

标签 cmake

foo/CMakeLists.txt , 基于 thisthis ,我有以下

SET (EXTERNAL_LIB_ROOT "../../external_libs/")

ADD_LIBRARY (avcodec-debug STATIC IMPORTED)

SET_PROPERTY (
    TARGET avcodec-debug PROPERTY IMPORTED_LOCATION
    ${EXTERNAL_LIB_ROOT}/libavcodec-0.8.10.a)

bar/CMakeLists.txt我有这个:
# old way uses system libraries
#TARGET_LINK_LIBRARIES (bar avformat avcodec avutil)

# new way uses local debug builds
TARGET_LINK_LIBRARIES (bar avformat avcodec-debug avutil)

当我跑 make我得到
/usr/bin/ld: cannot find -lavcodec-debug

如果我恢复到旧的方式,构建,触摸 foo/CMakeLists.txt和rebuild,CMake的配置输出表明构建系统正在找到avcodec-debug。

那么为什么我不能将它添加为依赖项呢?

最佳答案

正如Angew上面提到的,导入库的可见性不同,但您可以使用 GLOBAL 扩展它。修饰符。修改add_library可能就够了调用下一个方式:

ADD_LIBRARY(avcodec-debug STATIC IMPORTED GLOBAL)

关于CMake 找不到 IMPORTED 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23565564/

相关文章:

c++ - Target Boost::<library> 已有导入位置 + 链接错误

cmake 在 OS X 上找不到 gl.h

c++ - vcpkg添加新库但找不到

c++ - 无法在 ROS 中使用本地安装的 Protocol Buffers

c++ - 库标题和#define

c++ - 无法使用 cmake 使 QPrinter 链接

CMake 与有关生成的文件

c++ - 使用 cmake 在多个模块中使用实用程序库(仅 header )

gcc - 在 cmake 中检查 gcc 次要

cmake - 使用带有新命令 gtest_discover_tests 的 CMake/Ctest 的谷歌测试