[cmake-developers] Usage Requirements with Object Libraries

Brad King brad.king at kitware.com
Wed Apr 11 11:45:59 EDT 2018


On 04/11/2018 10:48 AM, Gößwein Matthias / eeas gmbh wrote:
> CMake Error: The inter-target dependency graph contains the following
> strongly connected component (cycle):
>   "lib1" of type OBJECT_LIBRARY
>     depends on "lib2" (strong)
>   "lib2" of type OBJECT_LIBRARY
>     depends on "lib1" (weak)
> At least one of these targets is not a STATIC_LIBRARY.  Cyclic
> dependencies are allowed only among static libraries.
> 
> add_library(lib1 OBJECT lib1.c)
> target_link_libraries(lib1 PUBLIC lib2)
> add_library(lib2 OBJECT lib2.c)
> target_link_libraries(lib2 PUBLIC lib1)
> 
> Is it possible to implement the same thing for object libraries too

For reference, the documentation of tll behavior for object libraries is here:

  https://cmake.org/cmake/help/git-master/command/target_link_libraries.html#linking-object-libraries

It states that "linking" object libraries to each other only propagates
usage requirements and does nothing special with the object files.
If there are dependencies like this then consumers would need to list
both object libraries together.  All object files would be listed once
on the link line and no repetition would be needed since explicitly
listing them guarantees they are linked.

Likely this will be okay.  However, I'd like to avoid supporting the
case until we gain more experience with the current design.  I've opened
an issue to track it here:

* OBJECT library circular target_link_libraries
  https://gitlab.kitware.com/cmake/cmake/issues/17905

Thanks,
-Brad


More information about the cmake-developers mailing list