问题
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?
回答1:
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".
来源:https://stackoverflow.com/questions/11346240/ranlib-and-static-library