这是重现问题的测试:
$ echo "void whatever() {}" > prog.c
$ gcc prog.c
这会在 GCC 4.8.4 上产生以下错误:
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
... etc ...
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
请注意,在 GCC 6.2.0 上,与此问题相关的错误消失了,它只生成:
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
许多用户已在 Stack Overflow 和其他地方多次报告过这一情况。
我想理解这个错误,不解决它(它已经解决了)。
执行此操作时会发生此错误gcc-4.8 prog.c
没有main()
内部功能prog.c
.
我在 binutils-source 包上对这个错误进行了文本搜索。乏味的谷歌搜索只给了我一个有用的链接帮助我更好地理解搬迁处理的概念 https://www.mirbsd.org/htman/i386/manINFO/bfdint.html#BFD-relocation-handling.
错误的数量似乎并不取决于程序,这表明所考虑的重定位并非源于此文件,而是缺失的直接结果main()
功能。我假设其中 3 个带有错误索引的重定位可能是为了main()
, argc
and argv
,但许多仍然存在,这只是一个未经证实的假设。
这超出了我的理解范围,任何可以帮助我更好地理解它的信息,或者 GCC 后续版本中发生的变化,都将受到热烈欢迎。