[CMake] Problem with link target over multiple libs

Philippe Fortier pfortier at resonantmedical.com
Tue Dec 21 10:20:57 EST 2004


Brad King wrote:

>
> It is a feature with a bug.  CMake maintains dependencies across 
> libraries introduced by TARGET_LINK_LIBRARIES commands.  That way if 
> staticB links to staticA then anything that links staticB will get 
> what it needs from staticA automatically.
>
> There are two potential bugs here:
>
> 1.) CMake does not keep track of whether libraries are static or 
> dynamic when maintaining this chaining information.  If DynB uses 
> symbols from staticA then they will be copied into DynB when it is 
> linked, but they will not be exported on all platforms.  If DynC uses 
> symbols from DynB then it is enough to link to DynB.  If DynC uses 
> symbols from staticA then it should explicitly link to it instead of 
> depending on the chain through DynB.  Therefore the proper behavior 
> may be to chain dependencies through static libraries but not through 
> shared libraries.  This may have unforseen consequences but should at 
> least be investigated.  Please submit this to the bug tracker here:
>
> http://www.cmake.org/Bug
>
> 2.) While the dependencies libraries are maintained, the locations of 
> the needed libraries are not.  This is a known problem and will 
> eventually be addressed.  It has not been a problem in our projects 
> because we usually use LIBRARY_OUTPUT_PATH to put all libraries in a 
> single directory in the build tree.  Then only one LINK_DIRECTORIES 
> entry is needed to point at this location.
>
> -Brad
>
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.

Thank you,

Philippe Fortier
Software Developer
Resonant Medical



More information about the CMake mailing list