在 foo/CMakeLists.txt
, 基于 this和 this ,我有以下
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/