【发布时间】:2018-04-10 16:38:50
【问题描述】:
我正在尝试使用 GCC 工具链将库 test.a 链接到可执行文件中。
我在使用 CMake 时从未遇到过类似的情况,一切似乎都运行顺利,直到
> [100%] Linking CXX executable test
ar qc lib/test.a CMakeFiles/test.dir/keys.cpp.o CMakeFiles/test.dir/test2.cpp.o CMakeFiles/test.dir/test3.cpp.o CMakeFiles/test.dir/test4.cpp.o CMakeFiles/test.dir/test5.cpp.o CMakeFiles/test.dir/test6.cpp.o
链接器抱怨的地方
> test.a: error adding symbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
test.a 包含以下目标文件:
> ar -t test.a
test1.cpp.o
test2.cpp.o
test3.cpp.o
test4.cpp.o
test5.cpp.o
test6.cpp.o
nm 无法识别文件的格式:
nm -s test.a
nm: test1.cpp.o: File format not recognized
nm: test2.cpp.o: File format not recognized
nm: test3.cpp.o: File format not recognized
nm: test4.cpp.o: File format not recognized
nm: test5.cpp.o: File format not recognized
nm: test6.cpp.o: File format not recognized
即使文件说这些是 ASCII 文件:
file test1.cpp.o
test1.cpp.o: ASCII text
我被卡住了。
如何找出问题所在?
【问题讨论】:
-
为什么是.o 的ASCII 文件?例如,在我机器上的 .o 上运行文件给我
ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped -
@Kevin 谢谢,您的评论是指向解决方案的正确指针。