[CMake] Problem with link target over multiple libs
Brad King
brad.king at kitware.com
Tue Dec 21 09:58:34 EST 2004
Philippe Fortier wrote:
> I am using CMake for quite a while now, but I just realized a weird
> behavior yesterday. I have three libraries :
>
> staticA
> DynB
> DynC
>
> In my cmakelists.txt of DynB, I link with library staticA. In the
> cmakelists.txt of DyncC, I link with DynB, when I generate my VC 7.net
> solution and projects files, DynC library is told to link with staticA
> wich cause an error because this library does not know where staticA is.
> I could fix the problem by specifying the location of staticA in the
> cmakelists.txt of DynC, but that is not correct, DynC should not need to
> no anything about staticA.
>
> Is it an error in CMake or a feature ? If so, could you just explain why
> CMake generates linking dependencies like that ?
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
More information about the CMake
mailing list