" _start"的多重定义使用-Wall而不是-o时出错

时间:2015-09-22 17:22:02

标签: c++

我的代码使用g++ -o pa1.out pa1.cpp编译并运行得很好但是当我使用g++ -Wall pa1.out pa1.cpp时会弹出一堆错误。我只有一个主要功能,代码在自己的项目中

这些都是我得到的错误:

g++ -Wall pa1.out pa1.cpp
pa1.out: In function `_start':
(.text+0x0): multiple definition of `_start'
/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
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/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/x86_64-linux-gnu/crt1.o:/build/buildd/eglibc-2.19/csu/../sysdeps/x86_64/start.S:118: first defined here
pa1.out: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_info): relocation 0 has invalid symbol index 7
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_info): relocation 1 has invalid symbol index 8
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_info): relocation 2 has invalid symbol index 9
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_ranges): relocation 0 has invalid symbol index 4
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_ranges): relocation 1 has invalid symbol index 4
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_ranges): relocation 2 has invalid symbol index 5
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_ranges): relocation 3 has invalid symbol index 5
/usr/lib/x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
pa1.out:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
pa1.out: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
pa1.out: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/local/google/home/haining/gcc-5.2/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtbegin.o:(.data+0x0): first defined here
pa1.out: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_line): relocation 0 has invalid symbol index 4
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o(.debug_line): relocation 1 has invalid symbol index 5
/usr/lib/x86_64-linux-gnu/crti.o:/build/buildd/eglibc-2.19/csu/../sysdeps/x86_64/crti.S:64: first defined here
/tmp/ccFEyUcw.o: In function `main':
pa1.cpp:(.text+0x0): multiple definition of `main'
pa1.out:(.text+0xf6): first defined here
/usr/local/google/home/haining/gcc-5.2/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
pa1.out:(.data+0x10): first defined here
/usr/bin/ld: error in pa1.out(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status

这是以最小的例子发生的:

int main() { }

1 个答案:

答案 0 :(得分:3)

-o-Wall不相关,一个提供输出文件名,另一个提示警告,而不是

g++ -Wall pa1.out pa1.cpp

你需要

g++ -Wall -o pa1.out pa1.cpp

没有 -o标志,您告诉gcc编译并链接您的源文件和可执行文件。