I am writing an application in C which used a global variable (a logfile structure). In my application I am loading shared libraries dynamically at runtime and I want to use a global variable pointing at the the same logfile structure to do logging in the shared library.
This doesn't seem to be possible in the easy approach:
Any hint how to fix this would be great.
Thank you!
You need to compile your main application with -rdynamic
flag (eg: gcc -g -rdynamic -o main main.c
, and to declare the global variable in your dynamic library with extern
.
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