'Workaround --exclude-libs not available on clang for OS X

I need to create a wrapper library which needs to use a different version of OpenSSL (BoringSSL), for reasons provided at "Wrapper Shared Objects" at [1].

The problem is that --exclude-libs is not available with clang for OS X, thus the symbols get exported which I must avoid.

What options do I have to workaround this, e.g. stripping symbols after the library has been built?

[1] https://wiki.openssl.org/index.php/Android



Solution 1:[1]

The macOS ld linker allows you to hide symbols from a specific static library, via -hidden-l instead of -l. Here's a quote from man ld on Mac:

     -hidden-lx  This is the same as the -lx for locating a static library,
                 but treats all global symbols from the static library as if
                 they are visibility hidden.  Useful when building a dynamic
                 library that uses a static library but does not want to
                 export anything from that static library.

So, don't use -lssl in your linker flags. Use -hidden-lssl.

Solution 2:[2]

I also use a different version of OpenSSL in my project. I build and link in static libraries with no reference to installed dylibs. This is completely independent of any other OpenSSL implementations that may be present on the machine. Will that strategy work for you? I guess I am wondering why you have to wrap a static library in a dynamic library? Why not just link the static library directly into the executable that will use it?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2