ranlib and static library

╄→尐↘猪︶ㄣ 提交于 2019-12-10 21:56:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!