0

I have some generated object files, from which I create a static library using:

 ar -r libmine.a *.o 

Afterwards I'm adding the index through:

 ar -s libmine.a

How can compare first command with second command and what additional functions gives me that index?

After use this command:

ar -r libmine.a *.o

i used this:

nm -s libmine.a 

and i get:

Archive index:
add in add.o
mul in mul.o
sub in sub.o
add.o:
0000000000000000 T add
mul.o:
0000000000000000 T mul
sub.o:
0000000000000000 T sub

I do next step ar -s libmine.a and after nm -s libmine.a i get the same output. Why? ar -r consists ar -s ?

Ice
  • 1,783
  • 4
  • 26
  • 52

1 Answers1

1

An archive with an index speeds up linking to the library, and allows routines in the library to call each other without regard to their placement in the the archive.

You can use nm -s or nm --print-armap to list the index table.

Oh, and the command for creating a library is ar -r <lib.a> <objects>. You mixed up the object and library name.

To elaborate on your "continuation": Yes, ar automatically persists and updates the index table for you, whenever ar makes changes to the archive. Most modern implementations of ar even automatically create such an index when first creating an archive, without you ever invoking ar -s.

Leandros
  • 16,805
  • 9
  • 69
  • 108