user485498
user485498

Reputation:

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 usage) expected a nice .exe file to appear. I have no idea what to do with this a.out file.

Upvotes: 5

Views: 2760

Answers (2)

Erik
Erik

Reputation: 91260

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.

Upvotes: 9

Trent
Trent

Reputation: 13477

a.out is the executable file.

run it:

./a.out

Upvotes: 3

Related Questions