G++ is deleting my Source Code

I normally compile my source code using "g++ name.cpp -o name". Recently, I tried using "g++ -o name.cpp name", and it deleted my source code. I'm really just interested in knowing why that happened, because I was following instructions from a good source I thought.

Here is the message it prints when I try to compile:

[c1010d20@ps11 lab2]$ g++ -o lab2.2.cpp lab2.2
lab2.2: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.text+0x0): first defined here
lab2.2: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.fini+0x0): first defined here
lab2.2:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
lab2.2: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.data+0x0): first defined here
lab2.2:(.rodata+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o:(.rodata+0x0): first defined here
lab2.2: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
lab2.2:(.data+0x8): first defined here
/usr/bin/ld: error in lab2.2(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
RTFM wrote:
-o file
Place output in file file. This applies to whatever sort of output is being
produced, whether it be an executable file, an object file, an assembler file
or preprocessed C code.


$ g++ -o lab2.2.cpp lab2.2
lab2.2 (the executable) is your input file.
lab2.2.cpp is your output file.


You may write
$ g++ -o lab2.2 lab2.2.cpp

Last edited on
Thank you! That was very helpful!
closed account (E0p9LyTq)
GCC tutorial
http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html
Topic archived. No new replies allowed.