CMake cyclic dependency error when user library name matches system library name

I have the following problem.

I am writing a CMakeLists.txt file to create my C ++ project, which consists of

  1. libhybris.so: a shared library with some exported functions.
  2. hybris: executable file that references libhybris.so
  3. A collection of different shared libraries that link to libhybris.so

The problem is that libhybris.so is dependent on libpcre (for regex features), so I have the following statements:

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

...

# Needed libraries
target_link_libraries( libhybris 
                       dl 
                       pcre 
                       pthread
                       readline )

And one of the common libraries from point 3 is called pcre.so, so I also have the following:

add_library( pcre SHARED ${PCRE_SOURCES} )

...

target_link_libraries( pcre
                       dl 
                       pcre 
                       curl
                       pthread
                       readline
                       ffi 
                       libhybris )

So, when I run "cmake.", I get the following error:

-- 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?

+3
2

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), .

+1

. , .

0

Source: https://habr.com/ru/post/1748603/


All Articles