[CMake] Transitive linking and static libraries

Giordano Khouri kgiordano at nikon.net
Wed Oct 16 15:34:29 EDT 2013


The static libraries must be compiled with -fvisibility=hidden. Symbols with default visibility are marked as "public" and will leak from a shared library. With hidden visibility, they symbols are marked as "private extern", allowing you to link with them, but not allowing them to leak from a shared library. Any time that shared libraries are involved, you will want hidden visibility and mark your public API functions with default visibility.





[http://download2.nikon.net/images/logo/bsymbol.gif]
Khouri Giordano
Software Technology Researcher

Nikon Inc.
1300 Walt Whitman Road
Melville NY 11747-3064

Office: 631-547-4335    Fax: 631-547-0361

kgiordano at nikon.net<mailto:kgiordano at nikon.net>




www.nikonusa.com






[http://download2.nikon.net/images/logo/nikon1AW1sig.jpg] <http://www.nikonusa.com/en/Nikon-Products/Product/Nikon1/V27669.27669/Nikon-1-AW1.html?cid=eml-0913-n1aw1-signature>
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of James Bigler
Sent: Wednesday, October 16, 2013 2:06 PM
To: cmake at cmake.org
Subject: [CMake] Transitive linking and static libraries

Is it possible to stop known static libraries from being carried through shared libraries?

add_library(mystatic1 STATIC ...)
add_library(mystatic2 STATIC ...)
add_library(myshared SHARED ...)
target_link_libraries(myshared mystatic1 mystatic2)
add_executable(myexe)
target_link_libraries(myexe myshared)

Once a shared library is created, all the information about what libraries are needed should be encoded in the shared library.  In addition if myexe links against only myshared then only the symbols being exported by myshared should be visible to myexe.

I'm seeing problems where symbols from mystatic1 are being seen by myexe, when myexe should only be seeing symbols from myshared.  This is because CMake links myshared, mystatic1, and mystatic2 to myexe all in the same link line.

James



CONFIDENTIAL:
This e-mail including any attachments is intended only for the party or parties to whom it is addressed and may contain information which is privileged and/or confidential. If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution, copying, or printing of any information contained in or attached to this e-mail is STRICTLY PROHIBITED and may constitute a breach of confidentiality and/or privilege. If you have received this e-mail in error, please notify immediately the sender by reply e-mail and then delete this e-mail and any attachments in their entirety from your system. Thank you. This e-mail message including any attachments is believed to be free of any viruses; however, it is the sole responsibility of the recipient to ensure that it is virus free, and Nikon does not accept any responsibility for any loss, disruption or damage to your data or computer system which may occur in connection with this e-mail including any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20131016/6ac0e792/attachment-0001.htm>


More information about the CMake mailing list