Reputation: 31
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?
Upvotes: 3
Views: 4744
Reputation: 5885
Normally you need to call some registration function in your application to generate such a reference. Of course if you don't have access to the code of the first library, you can only use the -g option as described by tommieb75.
Upvotes: 1
Reputation: 34592
Generally, the linker does strip out other symbols - mainly for
There are two trains of thoughts here:
In essence those two are mutually exclusive - you cannot have both combined.
So it depends on which switches did you use for this to happen. Usually, -g
switch is for internal debugging and testing prior to public release. The opposite would be something like this -O2
which makes the compiler smart enough to generate a executable that would be considered optimized such as removing dead variables, unrolling loops and so on.
Hope this helps and gives you the hint
Upvotes: 1
Reputation: 432
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.
Upvotes: 1