I have two files 37064544_p1.cpp
& 37064544_p2.cpp
with the same content as shown below :
int add(int x,int y)
{
return x+y;
}
I compiled them using
g++ -c 37064544_p2.cpp -o 37064544_p2.o
g++ -c 37064544_p2.cpp -o 37064544_p2.o
and added them to an archive using
ar -rsc lib37064544pf.a 37064544_p1.o 37064544_p2.o
And
$ nm -s lib37064544pf.a
gives me :
Archive index:
_Z3addii in 37064544_p1.o
_Z3addii in 37064544_p2.o
37064544_p1.o:
0000000000000000 T _Z3addii
37064544_p2.o:
0000000000000000 T _Z3addii
and
$ ar -t lib37064544pf.a
gives me
37064544_p1.o
37064544_p2.o
I have a driver which calls the _Z3addii
function which is compiled with
g++ -static 37064544driver.cpp -o 37064544driver.elf -L. -l37064544pf
Result is
Sum : 11
Questions
How is the symbol
_Z3addii
resolved ?- Is it according to archive index?
- Is it according to the order in which we populate the archive using
ar
?
How can I change this order?
- How can I prevent
ar
from having duplicate symbols?
Compiler : g++ 4.6.3