I have a C++ project with many libraries that is built with Clang using CMake. The purpose of this project is to compile library X
which I distribute to clients along with its API headers. The API itself is completely 'isolated' and depends only on C++ standard headers.
When building a static library for iOS I compile all the libraries (make install
) and then combine them into single static library using libtool -static
. When distributing it to clients I've faced a problem.
Suppose the libraries on which public library X
depends on internally are named A
and B
.
Also, suppose library A
is a popular library used by many people and the client happens to be linking library A
of different version to his executable along with library X
(which already has A
object files inside).
This results either in duplicate symbols or even worse - our library X
somehow starts calling functions from client's A
of different version sometimes resulting in crash (that happened with libpng library).
Question.
What is a proper way to create such an isolated static library that would expose (via nm
command and especially during the linking stage to the final executable) only the symbols that are present in the X
public API?
Would be great if it would be a compiler command that I could add to CMake configuration. Also, I really don't want to modify the source code (e.g. add namespaces and so on) as it's complicated for third party libraries.
I've been looking into symbol visibility, relocatable pre-linking, striping and other techniques but I'm not sure I'm on the right track as this problem must have happened before to many people and it's strange I failed to find a solution after many days of searching and experimenting.