Linux – Merge multiple .so shared libraries


Say I have and
Can I produce as a single shared library with all the functions exported by a and b, of course resolving all intra-dependencies (i.e. all functions of called by and the other way around)?

I tried

gcc -shared -Wl,soname, -o

but it doesn't work.

Same goes if I archive a.o and b.o in a.a and b.a (which shouldn't modify a.o and b.o), and do

gcc -shared -Wl,soname, -o a.a b.a


Best Solution

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 -Wl,--whole-archive a.a b.a -Wl,--no-whole-archive
Related Question