Include static lib in shared object?
-
24-05-2021 - |
Pregunta
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.
Solución
This really is a 2 step process:
ar -x mylib.a
gcc -shared *.o -o mylib.so
Otros consejos
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.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow