Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Static Library to a Shared Library?

I have a third-party library which consists mainly of a large number of static (.a) library files. I can compile this into a single .a library file, but I really need it to be a single .so shared library file.

Is there any way to convert a static .a file into a shared .so file? Or more generally is there a good way to combine a huge number of static .a files with a few .o object files into a single .so file?

like image 556
Eli Courtwright Avatar asked Mar 17 '09 17:03

Eli Courtwright


People also ask

What is the difference between static library and shared library?

Static libraries take longer to execute, because loading into the memory happens every time while executing. While Shared libraries are faster because shared library code is already in the memory. In Static library no compatibility issue has been observed.

Can a static library use a dynamic library?

Yes for instance when you call windows functions from within your static lib they are normally from some dynamic library so there should be no difference.

What are shared and static libraries?

Shared libraries are added during linking process when executable file and libraries are added to the memory. Static libraries are much bigger in size, because external programs are built in the executable file.


1 Answers

Does this (with appropriate -L's of course)

gcc -shared -o megalib.so foo.o bar.o -la_static_lib -lb_static_lib 

Not do it?

like image 91
dicroce Avatar answered Sep 18 '22 08:09

dicroce