Reputation: 43
I write a static library: libA.a. I have another application called B.o. B.o doesn't used any functions in libA.a. I want to combine libA.o into B.o, then I could call some stuff in libA.a by other methods, when B.o is running.
I write makefile like this: gcc B.c -o B.o -lA -u symbol_A
. Here -u is from GCC manual:
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
It suggests use -u to force linking unused library, and symbol_A is some symbol in libA.a
But it doesn't work. After linking, I can not find any LibA.a's stuff in B.o.
May anyone give me some hint?
p.s I am using GCC 3.4.4, eclipse+CDT under windows, and B.o will be deployed under linux.
Upvotes: 1
Views: 2280
Reputation: 3048
The explanation of the -u
flag from GCC means the following:
If you have a symbol aka variable or function that is defined in your source tell GCC to pretend that it is undefined so it takes the definition of such variable or function from the library you are linking.
So if your B.c
has nothing that may be defined in libA.a
the -u
flag won't help you since the symbol_A
is not needed by B.c
and by the same token B.o
, so will be simply ignored.
Upvotes: 1