[CMake] target_link_libraries chain dynamic->static

Alexander Neundorf a.neundorf-work at gmx.net
Sun May 20 07:56:58 EDT 2012


On Thursday 17 May 2012, Petr Kmoch wrote:
> Hi Anton,
> 
> you should look into target property LINK_INTERFACE_LIBRARIES (and its
> per-configuration variants) which controls "transitive linking."
> target_link_libraries() also accepts LINK_INTERFACE_LIBRARIES as an
> argument mode, which sets the property instead of linking.

No, this is a different problem.

Linking a shared library against static libraries does not have the effect 
that the object files of the static libs are included in the shared lib.
But this is probably what Anton expected.
So, since this does not happen, to resolve the functions when linking the 
executable, it also needs to link against the static libraries.
So this is correct.

"Convenience libraries" as they are called with autotools are not really 
supported with cmake.
You have two options:
1) simply compile all source files directly into the shared library. They can 
be in different directories, no problem.
2) since cmake 2.8.8: instead of creating static libs, create a "object" libs: 
add_library(.. OBJECT ...). This basically avoids the need for recompiling the 
source files if the files are otherwise built multiple times (which may happen 
with solution 1) ).

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120520/26af2808/attachment-0001.htm>


More information about the CMake mailing list