Linux Novice Question: GCC compiler output

I am a complete newbie to Linux. I have a mint on a laptop and recently played with it.

I wrote a simple C program and saved the file. Then at the command prompt I typed

gcc -c myfile 

and took out a file called a.out. I naively (after many years of using Windows) expected a good .exe file to appear. I do not know what to do with this a.out file.

+4
source share
2 answers

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 .

+7
source

a.out is an executable file.

run it:

 ./a.out 
+3
source

All Articles