Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static library symbols missing in linked executable

I am trying to link a statically created .a library with another piece of C code.

However, in the final executable several symbols (function names) are are found missing when seen with the nm command. This is due to the fact that the linker (gcc being called) is stripping the symbols which are not referenced in the other piece of C code that is being linked with the library. The function symbol that I am trying to find with the nm command is visible in the .a library.

How can I make the linker not strip the symbols omitted this way?

like image 432
VNL Avatar asked May 31 '26 21:05

VNL


1 Answers

Compile in gcc with -dynamic to force the compiler to include all symbols. But make sure that's what you really want, since it's wasteful.

Might be useful for some static factory patterns.

like image 125
Matthew Herrmann Avatar answered Jun 04 '26 12:06

Matthew Herrmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!