Question

Greetings all!

I'm using gcc on linux to create a shared library. The library itself has no code but links to a couple of static libraries(archives) also built using gcc. I need to export the static libs' symbols through my shared library. What happens is that the resulting shared lib is too small and it actually does not contain any of the symbols provided by the static libs mentioned above. I also tried with a map of exported symbols but that did not help at all. Could any of you suggest a solution!

10x in advance

Was it helpful?

Solution

You need the linker's --whole-archive option to pull in all of the static archives:

gcc -shared -o libwhatever.so -Wl,--whole-archive -lstatic -Wl,--no-whole-archive

The -Wl is needed because --whole-archive is a linker option.

In order to do this, the code in libstatic.a will need to have been properly compiled for use in a shared object (i.e. with -fpic on platforms that require that).

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