代码之家  ›  专栏  ›  技术社区  ›  Simone Margaritelli

自定义库名称与系统库相同时出现循环依赖项错误

  •  3
  • Simone Margaritelli  · 技术社区  · 16 年前

    我有以下问题。 我正在编写一个CMAKLISTS.txt来构建一个我的C++项目,它由

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

    问题是,libhybris.so依赖于libpcre(对于regexp功能),所以我有以下语句:

    # 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依赖项(system libpcre.so)与我的pcre.so是相同的,这并不明显。

    我怎么解决这个问题 没有 更改pcre.so名称?

    2 回复  |  直到 13 年前
        1
  •  1
  •   Johannes S. Ian Garrison    13 年前

    在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
  •  0
  •   Anatoli    16 年前

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

    推荐文章