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.

有帮助吗?

解决方案

This really is a 2 step process:

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top