You have to you build your application where you have a global variable with -rdynamic
option for g++
. This option instructs the linker (ld
) to add all symbols, not only used ones, to the dynamic symbol table of your application.
This is an example how I build my test C++ application that loads a shared library. The shared library uses a global variable in main.cpp
. So I have added -rdynamic
when build my main
application:
g++ -rdynamic -m64 -g main.cpp -o main -ldl
When g++
finds -rdynamic
it passes the flag -export-dynamic
to the ELF linker (ld
).
This is from man ld
(which actually creates the dynamic symbol table):
If you use "dlopen" to load a dynamic object which needs to refer back
to the symbols defined by the program, rather than some other dynamic
object, then you will probably need to use this option when linking
the program itself.
Useful links: