Is it possible to create a shared library by linking static libraries?

I have a bunch of static libraries (* .a) and I want to create a shared library (* .a) to link to these static libraries (* .a). How to do this in gcc / g ++? Thanks!

+7
source share
2 answers

You can (just extract all the .o files and associate them with -shared to make .so ), but whether it works and how well it works depends on the platform and whether the static library is compiled as position-independent code (PIC). On some platforms (e.g. x86_64), non-PIC code is not allowed in shared libraries and will not work (in fact, I think the linker will refuse to do .so ). On other platforms, non-PIC code will work in shared libraries, but a copy of the library inside the memory cannot be used between different programs that use it or even different instances of the same program, so this will lead to huge memory bloating.

+13
source

I do not understand why you could not just create your dynamic library files for .o files and links with;

 gcc -shared *.o -lstaticlib1 -lstaticlib2 -o mylib.so 
+6
source

All Articles