[CMake] Problem with link target over multiple libs
Brad King
brad.king at kitware.com
Tue Dec 21 10:37:02 EST 2004
Philippe Fortier wrote:
> But static libraries are not "linked", they are compiled then object
> files are packed together. So for all of my static libraries, we have
> over 20, I never use TARGET_LINK_LIBRARIES nor LINK_DIRECTORIES..... I
> only use them for dynamic libraries and executables..... I prefer to
> rely on the compiler/linker to tell me if a library is missing. In this
> way, I am sure that I use only necessary libraries. I will submit the
> bug to cmake.org/Bug for the dynamic libraries problem.
True, a static library is basically a tarball of object files, but CMake
tries to hide this and make it look like linking. Consider this case:
1.) ProjectA defines library A1 which provides a bunch of symbols.
2.) ProjectB developed by someone else creates an executable and links
to A1.
3.) ProjectA decides to split A1 into A1 and A2 with A2 providing some
symbols that A1 needs.
4.) Now ProjectB's executable fails to link even though it is only using
symbols from A1. The ProjectB author now needs to be aware of the
internal A2 library, which breaks encapsulation.
This is why CMake provides "linking" for static libraries. When
ProjectB links to A1 it will automatically add A2 after A1 to the link
line for the executable.
-Brad
More information about the CMake
mailing list