Linux Novice Question: GCC Compiler output
I am a complete novice with Linux. I have Mint on a laptop and have recently been playing around with it.
I wrote a simple C program and saved the file. Then in the command line I typed
gcc -c myfile
and out popped a file called a.out. I naively (after years of Windows us开发者_如何学运维age) expected a nice .exe file to appear. I have no idea what to do with this a.out file.
Name it with -o
and skip the -c
:
gcc -Wall -o somefile myfile
You should name your sourcefiles with a .c
extension though.
The typical way of compiling e.g. two source files into an executable:
#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 make this into a single step:
gcc -Wall -o myapp file1.c file2.c
Or, for your case with a single source file:
gcc -Wall -o myapp file.c
The -Wall
part means "enable (almost) all warnings" - this is a habit you should pick up from the start, it'll save you a lot of headaches debugging weird problems later.
The a.out
name is a leftover from older unixes where it was an executable format. Linkers still name files a.out
by default, event though they tend to produce ELF
and not a.out
format executables now.
a.out is the executable file.
run it:
./a.out
精彩评论