[CMake] Transitive linking

James Bigler jamesbigler at gmail.com
Fri Nov 18 15:35:07 EST 2011


I thought CMake knew how to not drag all the dependent libraries once you
linked an executable module.

add_library(A STATIC a.cpp)
add_library(B SHARED b.cpp)
target_link_libraries(B A)
add_library(C SHARED c.cpp)
target_link_libraries(C B)

add_executable(run run.cpp)
target_link_libraries(run C)

At this point I'm seeing that C links against B and A when I think it
should only link against B since A shouldn't be needed to link against B.
In addition when compiling run, it links against B and A.

/usr/bin/c++   -dynamiclib -Wl,-headerpad_max_install_names   -o libC.dylib
-install_name /Users/jbigler/tmp/code/cmake/translinking/build/libC.dylib
CMakeFiles/C.dir/c.cpp.o libB.dylib libA.a
/usr/bin/c++    -Wl,-search_paths_first -Wl,-headerpad_max_install_names
CMakeFiles/run.dir/run.cpp.o  -o run  libC.dylib libB.dylib libA.a

Is this the expected behavior?  I'm seeing this with CMake 2.8.5 on Mac.

Project attached.

Thanks,
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111118/99f243c8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: translinking.tar.gz
Type: application/x-gzip
Size: 504 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111118/99f243c8/attachment.bin>


More information about the CMake mailing list