Why is -rdynamic not exporting the symbols in .a files but is exporting the symbols in .o files ?
I have an app and a plug-in in a .so file. The main app is linked using a series of object files and one static library, like this:
CXXFLAGS = $(CXXFLAGS_COMMON) -rdynamic
STATICLIBS = ../Utilities/Utilities.a
...
all:
$(CXX) $(CXXFLAGS) -o $(SAMPLE) main.o $(STATICLIBS) $(SHAREDLIBS) $(INCLUDES)
(CXX is g++ 4.5.2 on Ubunut, I use mainly -std=c++Ox for compilation)
In this case, the symbols in Utilities.a are not exported (i.e. “objdump -t a.out | grep symbol” is empty).
If I use “ar x” to extract the .o files in the .a and link using only the .o’s, then the symbols are exported and found by the plug-ins (that are loaded with dlopen in case you wondered).
I have tried using -Wl,-export-dynamic but without success.
I do have a workaround, as mentionned, but I’d still wish to understand what I am missing. Thanks in advance !
Normally, the linker only includes those parts of static archives (
.afiles) which are referenced.To force the linker to include the entire contents of a
.afile, you can use the--whole-archivelinker option (so-Wl,--whole-archiveon the gcc command line).Note that
-Wl,--whole-archiveis position-sensitive on the command line — it only affects.afiles following it on the command line. Its effect may be subsequently turned off using-Wl,--no-whole-archive, if there are further static archives which you don’t want to be completely included.So, for instance, with your command: