【发布时间】:2016-08-23 16:30:46
【问题描述】:
我有一个供应商提供的库存档,已导入到我的项目中:
add_library(
lib_foo
STATIC
IMPORTED GLOBAL
)
set_target_properties(
lib_foo
PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_LIST_DIR}/vendor/foo.a"
)
set_target_properties(
lib_foo
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_LIST_DIR}/vendor"
)
当我尝试使用此库链接应用程序时,我收到 undefined reference to 'pthread_atfork' 链接器错误:
/usr/lib/libtcmalloc_minimal.a(libtcmalloc_minimal_internal_la-static_vars.o):
In function `SetupAtForkLocksHandler':
/tmp/gperftools-2.4/src/static_vars.cc:119:
undefined reference to `pthread_atfork'
../vendor/foo.a(platformLib.o): In function `foo::Thread::Impl::join()':
所以vendor/foo.a 依赖于pthread。
我试过target_link_libraries(lib_foo pthread) 但这不起作用,因为lib_foo 是IMPORTED 目标,而不是构建目标
CMake Error at libfoo/CMakeLists.txt:41 (target_link_libraries): Attempt to add link library "pthread" to target "lib_foo" which is not built in this directory.
问题:
如何将pthread 链接到lib_foo,或者指定依赖于lib_foo 的目标也依赖于pthread?
【问题讨论】: