5

I am trying to link a static library that I created, but I get this error.

libmine.a: could not read symbols: Archive has no index; run ranlib to add one

I tried to do ranlib libmine.a but nothing changed, it still gives the same error. How can I solve this problem?

pythonic
  • 20,589
  • 43
  • 136
  • 219
  • 1
    Why not simply `ar czvf libmine.a *.o`? Also see http://stackoverflow.com/questions/2765240/could-not-read-symbols-archive-has-no-index-run-ranlib-to-add-one –  Jul 05 '12 at 14:22
  • 2
    What is the output of `nm libmine.a`? I haven't run `ranlib` for about 15 years - it's no longer required as `ar` takes care of it. – trojanfoe Jul 05 '12 at 14:22

1 Answers1

5

To see the symbols in an archive, use nm.

nm -s libmine.a

<output>

The entry points to the subroutines should be labled "T" as in

00000000 T _sub1
00000019 T _sub2

What switches did you use in "ar" to make the static library? I usually use "ar -r" as in

ar -r libmine.a mine.o yours.o

If you are still having problems, add the "-s" option

ar -s -r libmine.a mine.o yours.o

Also, be sure that there are no other "libmine.a" files in the path, or make an explicit path to your "libmine.a". It is possible the linker is picking up a different "libmine.a".

dadinck
  • 1,118
  • 1
  • 7
  • 8