I am creating a shared object library which will be LD_PRELOADed with my program. In that shared library, I also want to use some variables from my program. What is the way of declaring such variables. Note that shared object library is compiled separately from my program.
Yes. You must link your program with --export-dynamic
to make the symbol table of the program accessible to the libraries opened. If you wish to control exactly which symbols are available and using libtool
for linking, you can use parameters like -export-symbols-regex
to specify which are available. If the symbols required by the library are not available when the program loads, it will fail with an undefined symbol. Some platforms require slightly different link flags (especially Windows). Consider using libtool
to make this easier if you are not already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With