preventing ld from discarding all symbols from archive files

Adam Williams broadcast@earthling.net
Wed Sep 5 19:12:00 GMT 2001


If I run the following command:


ld -shared -o sharedlibrary.so part1.a part2.a part3.a


the linker discards every symbol in the .a files and produces an empty
shared library called sharedlibrary.so, not what any sane person wants.

What the linker formally does is treat any object files as targets and
archive files as dependancies, removing all symbols from the archive
files which aren't used in the targets.  Since there are no objects
this clears all the symbols.

Is there any way to force ld to keep all the symbols in the archive
files?  It's really inconvenient to specify the name of all the object
files in multiple directories or require a runtime environment to 
contain 100 shared libraries.

The following flags have no success:

-Ur
-r
-export-dynamic




More information about the Binutils mailing list