Convert a Static Library to a Shared Library (create libsome.so from libsome.a): where’s my symbols?

Assuming you’re using the GNU linker, you need to specify the –whole-archive option so that you’ll get all the contents of the static archive. Since that’s an linker option, you’ll need -Wl to tell gcc to pass it through to the linker:

g++ -std=c++98 -fpic -g -O1 -shared -o libsome.so -Wl,--whole-archive libsome.a

If you were doing something more complicated where you want all of library some but only the part of library support needed by libsome, you would want to turn off whole archive after you’ve used it on libsome:

... -Wl,--whole-archive libsome.a -Wl,--no-whole-archive libsupport.a

If you’re not using the GNU linker, you’ll need to see if your linker supports it and what it’s called. On the Sun linker, it’s called -z allextract and -z defaultextract.

Leave a Comment