Merge multiple .so shared libraries Merge multiple .so shared libraries unix unix

Merge multiple .so shared libraries


Merging multiple shared libraries into one is indeed practically impossible on all UNIXen, except AIX: the linker considers the .so a "final" product.

But merging archives into .so should not be a problem:

gcc -shared -o c.so -Wl,--whole-archive a.a b.a -Wl,--no-whole-archive


In practice it is not possible.

From linker point of view, a SO library is a final product that does not contain relocation information required for linking.

If you have access to either source or object files for both libraries, it is straightforward to compile/link a combined SO from them.