我在链接链接上有错误,我已经阅读了很多帖子,但无法找到解决方案。
我在单独的文件夹中构建3个库:
lib_1为共享而没有依赖
lib_2共享需要lib_1(构建没有问题)
lib_3 as shared,需要lib_1和amp; lib_2
以下是简化的CMakelists.txt(路径已经过简化和三重检查,地雷也可以)
project (lib_1)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)
include_directories( lib_1/include/path/)
add_library(lib_1 SHARED lib_1/source/path)
====================================
cmake_minimum_required(VERSION 2.8)
project (lib_2)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)
include_directories( lib_2/include/path/)
add_library(lib_2 SHARED lib_2/source/path)
add_library(lib_1 SHARED IMPORTED)
set_property(TARGET lib_1 PROPERTY IMPORTED_LOCATION "lib_1/path/file.dylib")
=============
cmake_minimum_required(VERSION 2.8)
project (lib_3)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)
include_directories( lib_3/include/path/)
add_library(lib_3 SHARED lib_3/sources/path)
add_library(lib_1 SHARED IMPORTED)
set_property(TARGET lib_1 PROPERTY IMPORTED_LOCATION "/lib_1/path/file.dylib")
add_library(lib_2 SHARED IMPORTED)
set_property(TARGET lib_2 PROPERTY IMPORTED_LOCATION "/lib_2/path/file.dylib")
有趣的是我认为add_library& lib_3的set_property什么都不做,因为删除该行并没有改变错误,即我没有做我应该做的事情......但我不知道了。
(如果我一次构建所有文件,那么旁注代码会顺利运行,但我会在共享库中尝试一下)
参考错误:
[100%]链接CXX共享库lib_3.dylib
架构x86_64的未定义符号:
" LIB_1功能",引自: 在lib_3.cpp.o中 [...]
所有lib_1& lib_2函数标记为未定义