Hello,<div><br></div><div>While linking programs against static libraries built using llvm-ar and llvm-ranlib, I see an error message:</div><div><div>could not read symbols: Archive has no index; run ranlib to add one</div>
<div>collect2: ld returned 1 exit status</div></div><div><br></div><div>Using either /usr/bin/nm or llvm-nm (depending on the use of --emit-llvm flag to llvm-gcc), one of them is able to list the symbols in the archive file. However, the link step fails. Two sample runs follow. Am I missing any options? The source code was obtained from: <a href="http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html">http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html</a></div>
<div><br></div><div>== Without --emit-llvm ==</div><div><br></div><div><div>$ llvm-gcc -c ctest1.c ctest2.c </div><div><br></div><div>$ file *.o</div><div>ctest1.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped</div>
<div>ctest2.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped</div><div><br></div><div>$ llvm-ar cru libctest.a *.o</div><div><br></div><div>$ ls</div><div>ctest1.c  ctest1.o  ctest2.c  ctest2.o  libctest.a  prog.c</div>
<div><br></div><div>$ llvm-ar t libctest.a</div><div>ctest1.o</div><div>ctest2.o</div><div><br></div><div>$ llvm-nm libctest.a </div><div><br></div><div>$ nm libctest.a </div><div>nm: #_LLVM_SYM_TAB_: File format not recognized</div>
<div><br></div><div>ctest1.o:</div><div>0000000000000000 T ctest1</div><div><br></div><div>ctest2.o:</div><div>0000000000000000 T ctest2</div><div><br></div><div>$ llvm-ranlib libctest.a</div><div><br></div><div>$ llvm-gcc prog.c libctest.a -o p</div>
<div>libctest.a: could not read symbols: Archive has no index; run ranlib to add one</div><div>collect2: ld returned 1 exit status</div><div><br></div><div><br></div><div>== With --emit-llvm ==</div><div><br></div><div>$ llvm-gcc --emit-llvm -c ctest1.c ctest2.c </div>
<div><br></div><div>$ file *.o</div><div>ctest1.o: LLVM bitcode</div><div>ctest2.o: LLVM bitcode</div><div><br></div><div>$ llvm-ar cru libctest.a *.o</div><div><br></div><div>$ ls</div><div>ctest1.c  ctest1.o  ctest2.c  ctest2.o  libctest.a  prog.c</div>
<div><br></div><div>$ llvm-ar t libctest.a </div><div>ctest1.o</div><div>ctest2.o</div><div><br></div><div>$ llvm-nm libctest.a</div><div><br></div><div>libctest.a(ctest1.o):</div><div>         T ctest1</div><div><br></div>
<div>libctest.a(ctest2.o):</div><div>         T ctest2</div><div><br></div><div>$ nm libctest.a</div><div>nm: #_LLVM_SYM_TAB_: File format not recognized</div><div>nm: ctest1.o: File format not recognized</div><div>nm: ctest2.o: File format not recognized</div>
<div><br></div><div>$ llvm-ranlib libctest.a</div><div><br></div><div>$ llvm-gcc prog.c libctest.a -o p</div><div>libctest.a: could not read symbols: Archive has no index; run ranlib to add one</div><div>collect2: ld returned 1 exit status</div>
</div><div><br></div>