2015-09-22 4 views
1

Мой код компилируется и работает очень хорошо, используя g++ -o pa1.out pa1.cpp, но когда я использую g++ -Wall pa1.out pa1.cpp, появляется ошибка ошибок. У меня есть только один основной функции и код находится в своем собственном проектеОшибка «множественного определения _start» при использовании -Wall вместо -o

Все эти ошибки я получаю:

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() { } 

ответ

2

-o и -Wall не связаны друг с другом, один указывает имя выходного файла, другие - на предупреждения, а не

g++ -Wall pa1.out pa1.cpp 

вам нужно

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

Без -o флага, вы сообщаете GCC для компиляции и связать свой исходный файл с исполняемым файлом.

Смежные вопросы