[CMake] Transitive behavior of target_link_libraries between shared/static

Eric Noulard eric.noulard at gmail.com
Wed Jul 19 02:38:49 EDT 2017


2017-07-18 19:15 GMT+02:00 Hendrik Sattler <post at hendrik-sattler.de>:

>
>
> Am 18. Juli 2017 18:02:40 MESZ schrieb Eric Noulard <
> eric.noulard at gmail.com>:
> >2017-07-17 17:31 GMT+02:00 Robert Dailey <rcdailey.lists at gmail.com>:
> >
> >> Suppose I have the following:
> >>
> >> ```
> >> add_library( A STATIC ${files} )
> >>
> >> add_library( B SHARED ${more_files} )
> >> target_link_libraries( B PUBLIC A )
> >>
> >> add_library( C STATIC ${even_more_files} )
> >> target_link_libraries( C PUBLIC B )
> >>
> >>
> >> add_executable( D ${exe_files} )
> >> target_link_libraries( D PRIVATE C )
> >> ```
> >>
> >> Does the linker command for target `D` ever see target A's static
> >link
> >> library? I'm hoping the only thing the linker gets is `libB.so` and
> >> `libC.a`, without `libA.a`.
> >>
> >
> >I guess it does otherwise you may be missing symbols.
> >As explain by Peter some time ago:
> >  https://cmake.org/pipermail/cmake/2017-April/065347.html
> >when you
> >target_link_libraries( B PUBLIC A )
> >
> >with A being STATIC you do not really link A into B (which is shared in
> >your example)
>
> You confused PUBLIC and INTERFACE in your response.
> target_link_libraries( B PUBLIC A ) DOES link A into B but only the
> symbols needed by B.
>
> The link to the old post has it all right.
>

>
Thanks for the clarification Hendrik,

The thing I wasn't sure is that when B is shared and A is static

target_link_libraries(B PUBLIC A) or even
target_link_libraries(B PRIVATE A)

was effectively putting objects from A needed by B into B.

My use case was when B and A were STATIC.

I'll try an example in order to have concrete example at hand.

-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170719/4bd18500/attachment-0001.html>


More information about the CMake mailing list