Name it -o and skip -c :
gcc -Wall -o somefile myfile
You should call the source files the extension .c , though.
A typical compilation method, for example. two source files into an executable file:
#Compile (the -c) a file, this produces an object file (file1.o and file2.o) gcc -Wall -c file1.c gcc -Wall -c file2.c #Link the object files, and specify the output name as `myapp` instead of the default `a.out` gcc -o myapp file1.o file2.o
You can do this in one step:
gcc -Wall -o myapp file1.c file2.c
Or for your case with one source file:
gcc -Wall -o myapp file.c
The -Wall part means “turn on (almost) all warnings” - this is a habit that you should pick up from the very beginning, this will save you from many headaches that debug more strange problems later.
The name a.out is the remainder of the old unifications, where it was an executable format. Linkers still call the default a.out files, an event, although they tend to produce ELF format ELF rather than a.out .
source share