c - gcc 在一个小小的 hello world 程序中返回大量错误

标签 c gcc

我有点难过。这是我从 gcc 得到的错误

gcc -lm -g -o bin/tomashell obj/tomashell.o
obj/tomashell.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 21 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 22 has invalid symbol index 22
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crt1.o:/build/buildd-eglibc_2.11.2-10-i386-GapcyD/eglibc-2.11.2/csu/../sysdeps/i386/elf/start.S:119: first defined here
obj/tomashell.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crt1.o:(.rodata+0x0): first defined here
obj/tomashell.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crti.o:(.fini+0x0): first defined here
obj/tomashell.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
obj/tomashell.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crt1.o:(.data+0x0): first defined here
obj/tomashell.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.5/crtbegin.o:(.data+0x0): first defined here
obj/tomashell.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.5/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
obj/tomashell.o:(.dtors+0x4): first defined here
collect2: ld returned 1 exit status
make: *** [bin/tomashell] Error 1

And this is my entire code file:

#include <stdlib.h>
#include <stdio.h>

int main()
{
    printf("Hello, world!");
}

我完全不知道为什么这没有编译。我正在编译所有其他 C 应用程序。

最佳答案

obj/tomashell.o 不是目标文件而是可执行文件。您可能在编译时忘记使用 -c,因此(默认情况下)gcc 输出可执行文件而不是目标文件。

关于c - gcc 在一个小小的 hello world 程序中返回大量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7681110/

相关文章:

c - 标准 C 和现代编译器之间的差异

C: I/O - 从文件读取整数的最快/最佳方法

c++ - 是否假定C/C++中的所有函数都返回?

谁能指出是什么产生了这些错误的输出语句

c++ - GCC 内联汇编错误 : Cannot take the address of 'this' , 这是一个右值表达式

c - gcc 为 qsort 生成警告

c - 如何修改const变量的值?

c - 当我插入较大的数字时程序崩溃

c++ - GCC 和 Clang 不在 C++17 中编译 std::hash<std::nullptr_t>

c - 为什么需要为 GCC 中的代码覆盖传递两个编译器标志