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 u
A .o
file is ELF relocatable, and, a .so
file is ELF shared object. Whereas a .a
file is current archive. When the linker is passed the --export-dynamic
flag through the -rdynamic
from gcc
, it is looking for a dynamic object file.
I think the linker does not care to look into the archive and extract the symbols.
Normally, the linker only includes those parts of static archives (.a
files) which are referenced.
To force the linker to include the entire contents of a .a
file, you can use the --whole-archive
linker option (so -Wl,--whole-archive
on the gcc command line).
Note that -Wl,--whole-archive
is position-sensitive on the command line — it only affects .a
files 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:
$(CXX) $(CXXFLAGS) -o $(SAMPLE) main.o -Wl,--whole-archive $(STATICLIBS) -Wl,--no-whole-archive $(SHAREDLIBS) $(INCLUDES)