Reputation: 598
It seems that since I installed the latest version of GCC, I am no longer able to compile any C file if I want to change the output file. Let's take an example, file hello.c
:
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("hello\n");
}
If I do :
gcc hello.c
It works fine and I have the a.out
output. But if I want to change the name of the output, I should basically do :
gcc -o hello.c hello
Am I right?
If so, I get this error :
gcc: error: hello: No such file or directory
gcc: fatal error: no input files
compilation terminated
For another example, it goes totally WTF :
gcc -o Simplexe.c Simplexe
Simplexe: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
Simplexe: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
Simplexe: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
Simplexe:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
Simplexe: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
Simplexe: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
Simplexe:(.dtors+0x8): first defined here
/usr/bin/ld: error in Simplexe(.eh_frame); no .eh_frame_hdr table will be created.
I have never seen something like that, and it deleted my source file. I got caught once, I will never be anymore.
Upvotes: 0
Views: 6469
Reputation: 6327
-o specified output file, which is hello.c in your case, so you are trying to compile file hello, which doesn't exist. Correct command would be:
gcc hello.c -o hello
Upvotes: 1
Reputation: 74078
Change
gcc -o hello.c hello
to
gcc -o hello hello.c
-o
is followed by the target, not the source.
Your second case could occur, if the target Simplexe
exists and now gcc tries to link this again into the "target" Simplexe.c
, but that's just a guess.
Upvotes: 4