Hi,

It is perfectly normal that CMake requires static library to be exported when 
command ’target_link_libraries(fooshared barstatic)’ is specified because this 
is equivalent to command 'target_link_libraries(fooshared PUBLIC barstatic)’.

As you have already discovered, using command 'target_link_libraries(fooshared 
PRIVATE barstatic)’ avoids exporting of barstatic library.
Now, I think you did a wrong diagnostic regarding your link problems with this 
signature. Symbols visibility is not changed by specifying ‘PRIVATE’ but link 
commands are changed. With ‘PRIVATE’, the link command for your executable do 
not contains anymore a reference to barstatic library. And the ‘fooshared’ 
library will contains only objects from ‘barstatic’ needed to solved 
unreferenced symbols (so may be not all objects from ‘barstatic’).

So to solve your problem you have two possibilities:


1. Specify ‘barstatic’ library  as dependency of your executable, i.e. 
'target_link_libraries(exec PRIVATE fooshared barstatic)’.
2. Ensure that all objects of `barstatic` are included in your ‘fooshared’ 
library. For that purpose, you can create `barstatic` as OBJECT library and 
include all objects in your ‘fooshared’ library using pattern 
‘add_library(fooshared SHARED .. $<TARGET_OBJECTS:barstatic> …)’. But the most 
simple is, may be, to put directly all your sources in ‘fooshared’ library.


Le 28 févr. 2019 à 08:25 +0100, Lassi Niemistö <lassi.niemi...@wapice.com>, a 
écrit :
> Hello,
>
> The cmake "users" list did not wake any replies, so posting here as a 
> possible bug:
>
> I use CMake 3.13RC1. My project produces, installs and exports a shared 
> library target "fooshared". Some logical parts of "fooshared" are reused in 
> an executable, so I have placed those sources into an internal static library 
> target "barstatic". I have used target_link_libraries(fooshared barstatic) to 
> make this work.
>
> Problem: when I try to:
> install(TARGETS fooshared DESTINATION <dest> EXPORT myexport)
> install(EXPORT myexport DESTINATION <dest>)
> ..I get a whine about dependency to "barstatic" which is not in the export 
> group "myexport".
>
> I wouldn't like to export "barstatic" at all, it should remain under the 
> hood. I tried to use target_link_libraries(fooshared PRIVATE barstatic) which 
> cut the export chaining, but then symbols from "barstatic" were not available 
> for users of "fooshared" anymore. So I worked around this by converting 
> "barstatic" into an object library, but it feels ugly.
>
> Why would CMake require exporting statically linked dependency targets among 
> the targets that use them? Feels like a bug to me.
>
> Regards,
> -Lassi Niemistö
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake-developers
-- 

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:
https://cmake.org/mailman/listinfo/cmake-developers

Reply via email to