<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Hi,
<div><br /></div>
<div>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)’.</div>
<div><br /></div>
<div>As you have already discovered, using command 'target_link_libraries(fooshared PRIVATE barstatic)’ avoids exporting of barstatic library.</div>
<div>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 <b>do not contains anymore a </b>reference to barstatic library. And the ‘fooshared’ library will contains <b>only</b> objects from ‘barstatic’ needed to solved unreferenced symbols (so may be not all objects from ‘barstatic’).</div>
<div><br /></div>
<div>So to solve your problem you have two possibilities:</div>
<div><br /></div>
<div>
<ol>
<li>Specify ‘barstatic’ library as dependency of your executable, i.e. 'target_link_libraries(exec PRIVATE fooshared barstatic)’.<br /></li>
<li>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.</li>
</ol>
<div><br /></div>
</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Le 28 févr. 2019 à 08:25 +0100, Lassi Niemistö <lassi.niemisto@wapice.com>, a écrit :<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">Hello,<br />
<br />
The cmake "users" list did not wake any replies, so posting here as a possible bug:<br />
<br />
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.<br />
<br />
Problem: when I try to:<br />
install(TARGETS fooshared DESTINATION <dest> EXPORT myexport)<br />
install(EXPORT myexport DESTINATION <dest>)<br />
..I get a whine about dependency to "barstatic" which is not in the export group "myexport".<br />
<br />
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.<br />
<br />
Why would CMake require exporting statically linked dependency targets among the targets that use them? Feels like a bug to me.<br />
<br />
Regards,<br />
-Lassi Niemistö<br />
--<br />
<br />
Powered by www.kitware.com<br />
<br />
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br />
<br />
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br />
<br />
CMake Support: http://cmake.org/cmake/help/support.html<br />
CMake Consulting: http://cmake.org/cmake/help/consulting.html<br />
CMake Training Courses: http://cmake.org/cmake/help/training.html<br />
<br />
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br />
<br />
Follow this link to subscribe/unsubscribe:<br />
https://cmake.org/mailman/listinfo/cmake-developers<br /></blockquote>
<div></div>
</div>
</body>
</html>