It’s possible to pass --export-dynamic
to ld
and this will export symbols in the program (so that they are available to any shared libraries loaded at run-time):
$ cat > test.c
void foo() {}
int main() { foo(); }
^D
$ gcc test.c
$ nm -D a.out | grep foo
…nothing. And now:
$ gcc -Wl,--export-dynamic test.c
$ nm -D a.out | grep foo
0000000000001129 T foo
…works.
This is documented in https://sourceware.org/binutils/docs-2.34/ld/Options.html#Options
Is it possible to just export symbols from one particular static library?
Given like:
$ gcc myprogram.cc lib1.a lib2.a lib3.a
Say I just wanted to export symbols in the program from lib2.a, but not lib1.a or lib3.a?
I tried:
$ gcc myprogram.cc lib1.a -Wl,--export-dynamic lib2.a -Wl,--no-export-dynamic lib3.a
but it doesn’t work, it looks like --export-dynamic
is global.
(The documentation mentions --dynamic-list=listfile
but I didn’t understand the format of the file, or how to extract the symbol list from the static library?)