[CMake] Bad documentation of the LINK_INTERFACE_LIBRARIES property and other transitive linking topics
Michael Wild
themiwi at gmail.com
Wed Nov 23 04:44:22 EST 2011
On 11/23/2011 10:25 AM, Alan W. Irwin wrote:
> cmake-2.8.6 has the following documentation of the
> LINK_INTERFACE_LIBRARIES property for targets:
>
> LINK_INTERFACE_LIBRARIES
> List public interface libraries for a shared library or executable.
>
> By default linking to a shared library target transitively links to
> targets with which the library itself was linked. For an executable
> with exports (see the ENABLE_EXPORTS property) no default transitive
> link dependencies are used. This property replaces the default
> transitive link dependencies with an explicit list. When the target
> is linked into another target the libraries listed (and recursively
> their link interface libraries) will be provided to the other target
> also. If the list is empty then no transitive link dependencies
> will
> be incorporated when this target is linked into another target
> even if
> the default set is non-empty. This property is ignored for STATIC
> libraries.
>
> I believe the reference to executables above is just plain
> wrong/misleading. For example, the FAQ states that
> LINK_INTERFACE_LIBRARIES simply lists "the libraries that should be
> transitively included in the link by CMake" with the clear implication
> (also confirmed by experiment below) that this target property affects
> _everything that links to the target whose property is being set_.
> But nothing links to an executable so why are executables mentioned at
> all?
That's not true. See the ENABLE_EXPORTS target property.
[...]
>
> In sum, from this experiment it looks like I will have to set
> LINK_INTERFACE_LIBRARIES to empty for all PLplot library targets that
> depend on other library targets (e.g., B, C, D, and E, above, but _not_
> main or A) created by our build system to comprehensively turn off
> transitive linking and avoid overlinking that rpmlint is complaining
> about.
Transitive linking is a tricky issue, especially if the new
--no-copy-dt-needed-entries default is active which means that if you
have e.g. a library A, a library B that links against A and an
executable C that uses symbols from both, A and B but only directly
links against B, you will get a linking error if --as-needed is enabled.
However, CMake can't know for you whether C actually needs to be linked
against A, so it takes the safe route. The alternative would be to not
do it, but then you would need to explicitly link C against A. See
http://wiki.debian.org/ToolChain/DSOLinking for more details.
Michael
More information about the CMake
mailing list