【问题标题】:CMake cyclic dependency error when a custom library name is the same as a system library自定义库名称与系统库相同时的CMake循环依赖错误
【发布时间】:2011-02-28 00:15:52
【问题描述】:

我正在编写一个 CMakeLists.txt 文件来构建我的 C++ 项目,该项目由

  1. libhybris.so:具有一些导出函数的共享库。
  2. hybris:链接到 libhybris.so 的可执行文件
  3. 一组链接到 libhybris.so 的各种共享库

问题在于,libhybris.so 依赖于 libpcre(用于正则表达式功能),所以我有以下语句:

# libhybris.so generation
add_library( libhybris 
             SHARED 
             ${LIB_SOURCES} )

...

# Needed libraries
target_link_libraries( libhybris 
                       dl 
                       pcre 
                       pthread
                       readline )

第 3 点中的共享库之一称为 pcre.so,所以我也有以下内容:

add_library( pcre SHARED ${PCRE_SOURCES} )

...

target_link_libraries( pcre
                       dl 
                       pcre 
                       curl
                       pthread
                       readline
                       ffi 
                       libhybris )

所以,当我运行“cmake .”时,出现以下错误:

-- Configuring done
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "libhybris" of type SHARED_LIBRARY
    depends on "pcre"
  "pcre" of type SHARED_LIBRARY
    depends on "libhybris"
At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.

因为 CMake 认为 libhybris.so pcre 依赖项(系统 libpcre.so)与我的 pcre.so 相同,显然不是。

如何在不更改 pcre.so 名称的情况下解决此问题?

【问题讨论】:

    标签: c++ cmake shared-libraries cyclic-dependency


    【解决方案1】:

    在 CMake 中,推荐的方法是使用完整路径指定任何链接库。要获取系统库的完整路径,您可以使用FIND_PACKAGE(...)(如果支持)或直接使用FIND_LIBRARY(...)

    例如,

    FIND_LIBRARY( PCRE_SYSTEM_LIB pcre )
    
    ADD_LIBRARY( libhybris SHARED ${LIB_SOURCES} )
    TARGET_LINK_LIBRARIES( libhybris
                           ${PCRE_SYSTEM_LIB}
                           ......
                          )
    

    这将阻止 CMake 将其识别为目标的内容 (nameley pcre) 扩展到该目标的完整路径。

    【讨论】:

      【解决方案2】:

      这取决于您的开发环境。您可以设置构建路径来克服这些困难。

      【讨论】:

      • 如果我没有明确设置名称(例如给出 libhybris.so 的完整路径),cmake 将无法将 libhybris.so 识别为 pcre.so 的依赖项,我已经尝试过了.
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 2018-05-17
      相关资源
      最近更新 更多