相关疑难解决方法(0)

CMake:向IMPORTED库添加依赖项

我有一个供应商提供的库存档,我已导入到我的项目中:

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"
    )
Run Code Online (Sandbox Code Playgroud)

当我尝试使用此库链接应用程序时,我收到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()':
Run Code Online (Sandbox Code Playgroud)

所以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.
Run Code Online (Sandbox Code Playgroud)

题:

如何链接pthreadlib_foo,或指定使用的依赖关系的目标lib_foo也对并行线程的依赖?

c++ cmake

8
推荐指数
1
解决办法
4198
查看次数

标签 统计

c++ ×1

cmake ×1