Quantcast

Question about transitive deps and static libs.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about transitive deps and static libs.

Eric Noulard
I have a question concerning the transitive linking of dependence and static libs.

I'm working a on prokect where some shared lib are linked to static lib (do not ask me why).
So I do:

set(CMAKE_POSITION_INDEPENDENT_CODE True)

then I have a bunch of libraries (either static or shared) which depends on each other.
I use PRIVATE and PUBLIC specification with target_link_librairies.

Now I expected that the transitive link properties would be fullfilled simply i.e. that
when some target LIB1 is PRIVATEly link against say pthread. Then if a another
lib LIB2 is linked against LIB1 then then "pthread" wouldn't be dragged into the link
interface of LIB2.

It seems that this is not as simple as I thought and as soon as LIB1 is static
then LIB2 gets the dependency (be it PRIVATE or PUBLIC)...

Find attached a small example.

Is this a bug, a feature or something I didn't catch?

 
--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

privpubdeps.tgz (758 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about transitive deps and static libs.

Eric Noulard
Answering to myself.

This mail by Craig explains a lot:

Sorry for the noise. I guess I have my answer in there.
I'll try to propose a documentation update based on Craig's explanation because, 

does not contains clues on specific treatment for static libs.




2017-04-18 16:30 GMT+02:00 Eric Noulard <[hidden email]>:
I have a question concerning the transitive linking of dependence and static libs.

I'm working a on prokect where some shared lib are linked to static lib (do not ask me why).
So I do:

set(CMAKE_POSITION_INDEPENDENT_CODE True)

then I have a bunch of libraries (either static or shared) which depends on each other.
I use PRIVATE and PUBLIC specification with target_link_librairies.

Now I expected that the transitive link properties would be fullfilled simply i.e. that
when some target LIB1 is PRIVATEly link against say pthread. Then if a another
lib LIB2 is linked against LIB1 then then "pthread" wouldn't be dragged into the link
interface of LIB2.

It seems that this is not as simple as I thought and as soon as LIB1 is static
then LIB2 gets the dependency (be it PRIVATE or PUBLIC)...

Find attached a small example.

Is this a bug, a feature or something I didn't catch?

 
--
Eric



--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about transitive deps and static libs.

Petr Kmoch
Hi,

I will offer an alternative phrasing based on what makes me personally understand this best. It might potentially be useful for the documentation update you're planning.

`target_link_libraries(A B)` specifies that the code in A needs B to be added to the produced binary when the binary is *linked*. However, static libraries are not produced by linking, but by an archiver or librarian tool. Therefore, B needs to be present for the actual linking step when this happens further down the chain (when linking an executable or shared library), regardless of the "privacy" of B in A.

Petr

On 18 April 2017 at 17:44, Eric Noulard <[hidden email]> wrote:
Answering to myself.

This mail by Craig explains a lot:

Sorry for the noise. I guess I have my answer in there.
I'll try to propose a documentation update based on Craig's explanation because, 

does not contains clues on specific treatment for static libs.




2017-04-18 16:30 GMT+02:00 Eric Noulard <[hidden email]>:
I have a question concerning the transitive linking of dependence and static libs.

I'm working a on prokect where some shared lib are linked to static lib (do not ask me why).
So I do:

set(CMAKE_POSITION_INDEPENDENT_CODE True)

then I have a bunch of libraries (either static or shared) which depends on each other.
I use PRIVATE and PUBLIC specification with target_link_librairies.

Now I expected that the transitive link properties would be fullfilled simply i.e. that
when some target LIB1 is PRIVATEly link against say pthread. Then if a another
lib LIB2 is linked against LIB1 then then "pthread" wouldn't be dragged into the link
interface of LIB2.

It seems that this is not as simple as I thought and as soon as LIB1 is static
then LIB2 gets the dependency (be it PRIVATE or PUBLIC)...

Find attached a small example.

Is this a bug, a feature or something I didn't catch?

 
--
Eric



--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...