MantisBT - CMake
View Issue Details
0013211CMakeCMakepublic2012-05-10 21:362012-10-01 13:22
thanil 
 
normalminoralways
closedno change required 
Apple MacMac OS X10.7.3
CMake 2.8.8 
 
0013211: CMake should not link shared libraries recursively
If target A depends on a shared library B and B depends on a shared library C, then CMake will create linker directives to link A to both B and C, when it should only link A to B. This creates unnecessary dependencies in the case of shared libraries.
Attached file contains example CMake project with an executable A and two shared libraries B and C.
Once cmake has been run from directory xxx
xxx/CMakeFiles/a.dir/link.txt contains the following line:

/usr/bin/gcc -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/a.dir/a.c.o -o a b/liblibb.dylib b/c/liblibc.dylib

which shows that A will be linked to C when there is no reason to do so since these are shared libraries.
No tags attached.
gz cmake_link_bug.tar.gz (1,399) 2012-05-10 21:36
https://public.kitware.com/Bug/file/4326/*
Issue History
2012-05-10 21:36thanilNew Issue
2012-05-10 21:36thanilFile Added: cmake_link_bug.tar.gz
2012-05-11 02:42Mathieu MalaterreNote Added: 0029466
2012-05-11 07:53Brad KingStatusnew => resolved
2012-05-11 07:53Brad KingResolutionopen => no change required
2012-10-01 13:22David ColeNote Added: 0031126
2012-10-01 13:22David ColeStatusresolved => closed

Notes
(0029466)
Mathieu Malaterre   
2012-05-11 02:42   
When all else failed, read the instructions:

$ cmake --help-property LINK_INTERFACE_LIBRARIES
cmake version 2.8.7
  LINK_INTERFACE_LIBRARIES
       List public interface libraries for a shared library or executable.

       By default linking to a shared library target transitively links to
       targets with which the library itself was linked. For an executable
       with exports (see the ENABLE_EXPORTS property) no default transitive
       link dependencies are used. This property replaces the default
       transitive link dependencies with an explicit list. When the target
       is linked into another target the libraries listed (and recursively
       their link interface libraries) will be provided to the other target
       also. If the list is empty then no transitive link dependencies will
       be incorporated when this target is linked into another target even if
       the default set is non-empty. This property is initialized by the
       value of the variable CMAKE_LINK_INTERFACE_LIBRARIES if it is set when
       a target is created. This property is ignored for STATIC libraries.
(0031126)
David Cole   
2012-10-01 13:22   
Closing resolved issues that have not been updated in more than 4 months.