i tried making library with
ar -r -c -s libtestlib.a *.o
as given in this tutorial http://matrixprogramming.com/Tools/CompileLink.html
I was using MinGW to compile a windows app when I got the error, so I found the built-in MinGW commands:
i686-w64-mingw32-ar
And
x86_64-w64-mingw32-ar
Try using those instead of ar
if you encounter the problem in MinGW. They both fixed the question's problem for me.
libtool
also has an useful option:
-export-symbols-regexp
.
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.
I ran into the exact same problem when trying to compile the NBIS libraries. There is an option for
make install LIBNBIS=yes
which creates a single archive containing the other archive files. The gcc linker does not handle this gracefully and just emits the Archive has no index message. The fix is to leave the archives as separate files
make install LIBNBIS=no
Then just link the application to the required archive(s). The archive feed order is important to be sure that the linker identifies the required dependencies, then resolves them as it processes the .a files.