Linker option on linux to load all symbols

jamie_lynn
jamie_lynn used Ask the Experts™
on
Hi,

When creating a shared library, what is the linker option to add all the symbols?
I tried --export-dynamic but it didn't work for me..
I am using linux  2.6.5

Thanks
Jamie
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
Assuming you use gcc for linking, that should be :

        -Wl,-export-dynamic

which passes the --export-dynamic option along to the linker.

Author

Commented:
It isn't working for me..

So i am building one shared libray from 3 static libraries.
i.e. Building libsh.so from a.a, b.a, c.a,  and xxx.c
The missing symbols are from the static library.  If a use the symbol in xxx.c, then of course the shared library has that symbol.  If i don't use it, then it is missing.

I tried -Wl,-export-dynamic and -rdynamic when building libsh.so, but didn't work

Someone told me to include a symbol file... Is that true?
Top Expert 2009

Commented:
Can you post the exact commands you use to build the shared library ?
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
gcc -shared -static-libgcc -Wl,-export-dynamic -L/space/openldap/linux86w -L/space/libcommonssl/linux86w -o libsh.so xxx.o /space/libs/a.a /space/libs/b.a /space/libs/c.a -commonssl2 -rdynamic
I found the answer. You have to use --whole-archive

First, gcc doesn't know about this option, so you have to use -Wl,-whole-archive. Second, don't forget to use -Wl,-no-whole-archive after your list of archives, because gcc will add its own list of archives to your link and you may not want this flag to affect those as well.

Author

Commented:
The whole-archive option included all the symbols.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial