Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge multiple .so shared libraries

Say I have a.so and b.so. Can I produce c.so 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 b.so called by a.so and the other way around)?

I tried

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

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,c.so -o c.so a.a b.a

Thanks

like image 915
Metiu Avatar asked May 27 '09 10:05

Metiu


People also ask

Are shared and dynamic libraries the same?

Dynamic libraries (also called shared libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables, and the like) required by the program, are either linked into the program or in one of its dynamic libraries.

Is .so a shared library?

A shared library(. so) is a library that is linked but not embedded in the final executable, so will be loaded when the executable is launched and need to be present in the system where the executable is deployed.

Can a shared library depend on another shared library?

However, most shared library systems are restricted in that they only allow a single level of dependencies. In these systems, programs may depend on shared libraries, but shared libraries may not depend on other shared libraries.

Is .so a dynamic library?

Shared libraries are also called dynamic libraries. These shared libraries are linked in at runtime by the dynamic linker available on the operating system. Shared libraries usually end with the . so extension — an example is libboost.5.6.so.


1 Answers

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 
like image 186
Employed Russian Avatar answered Oct 02 '22 18:10

Employed Russian