tags:

views:

455

answers:

1

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

+3  A: 

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.

Jasmeet
ar -t libtestlib.aaccrpt.ocharclass.oci.odist.oedorpt.olist.osort.ostopword.osync.otext.ounicode.outil.owacrpt.oword.o
indu
That looks good as well. I suggest you rebuild the archive or try ar -s libtestlib.a to rebuild just the index. Also you can list the symbols from your object files and libraries via nm, by doing nm libtestlib.a or nm accrpt.o for example. Lets see if this helps to debug the problem.
Jasmeet
nm libtestlib.a nm: accrpt.o: File format not recognizednm: charclass.o: File format not recognizednm: ci.o: File format not recognizednm: dist.o: File format not recognizednm: edorpt.o: File format not recognizednm: list.o: File format not recognizednm: sort.o: File format not recognizednm: stopword.o: File format not recognizednm: sync.o: File format not recognizednm: text.o: File format not recognizednm: unicode.o: File format not recognizednm: util.o: File format not recognizednm: wacrpt.o: File format not recognizednm: word.o: File format not recognized
indu
Looks like your object files are not in the right format. Maybe they were compiled for a different platform ?. Try file stopword.o to see the format of the object files. Anyways you will need to recompile these, this of course requires having the source files. After that create the static library and link it with your application.
Jasmeet
Thank you Jasmeet. It worked. As you suggested,I recompiled those files and added to library.
indu
Good to hear that. I updated the answer to reflect our discussion here.
Jasmeet