main:so reso
gcc -Wl,--export-dynamic -o main main.c -ldl
so:so.c
gcc --shared -fPIC -o libso.so $<
reso:reso.c
gcc --shared -fPIC -o libreso.so $<
Correct solution is to add -rdynamic
to the link command of the main executable. This will add appropriate option to ld
(which, when using GNU ld
, happens to be --export-dynamic
).
Adding --export-dynamic
directly is technically incorrect: it's a linker option, and so should be added as -Wl,--export-dynamic
, or -Wl,-E
. This is also less portable than -rdynamic
(other linkers have an equivalent, but the option itself is different).