Question

I would like to compile a bunch of static libs into a shared object. So far I have

g++ -Wl -shared -fPIC -o myshared.so objs/*.o

Where the objs/*.o above contains all the object files extracted from the various static libs using ar.

UPDATE: basically, I'm wondering if I might be able to use the .a files directly on the command line without having to extract them.

Was it helpful?

Solution

This really is a 2 step process:

ar -x mylib.a
gcc -shared *.o -o mylib.so

OTHER TIPS

The reason you cannot use gcc -shared -o foo.so foo.a is because archives are treatment differently in that object files from the archive are only used to resolve undefined symbols — of which there are none, since you specified no prior .o files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top