Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

gcc - could not read symbols: Archive has no index; run ranlib to add one

i tried making library with

ar -r -c -s libtestlib.a *.o

as given in this tutorial http://matrixprogramming.com/Tools/CompileLink.html

But on linking with library following error comes

g++ -o uni2asc uni2asc.o -L../Modules -ltestlib

../Modules/libtestlib.a: could not read symbols: Archive has no index; run ranlib to add one
collect2: ld returned 1 exit status

i tried with ranlib also but still the error comes.. im working with ubuntu9.10 Please suggest me some solution for this

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your archive command looks fine, can you try the following. 1) Get the object files in the archive/static library

ar -t libtestlib.a

2) For each object file (say foo.o) from step 1

file foo.o 

This will tell you the format of the object file. If the object file was compiled for a different platform, this would cause a failure to build the index for the archive. To correct this you would need to recompile these files.
3) For each object file from step 1, do

nm foo.o

This will list the symbols exported from the file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...