Click here to Skip to main content
15,065,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have just started learning programming on Linux using C, I have found that on compiling the source code file i.e.., xyz.c using the command gcc xyz.c we get an executable file a.out which has an equivalent hex code in it, and which is understandable by cpu.

here are my doubts
1. what is the meaning of -E, -S and -c
2. when try compiling directly using command gcc xyz.c it creates an executable file named a.out which has equivalent hex code in it, so what is the difference between a.out and .o extension file.
3. what is the exact meaning of -o in the linux commnand

What I have tried:

but when I have tried this procedure to find and observe what is happening in the procedure of compilation
step 1: gcc -E xyz.c -o xyz.i
its creates an .i extension file which has an expanded source code.
step 2: gcc -S xyz.i -o xyz.s
its creates an .s extension file which has an equivalent assembly code.
step 3: gcc -c xyz.c -o xyz.o
its creates an object file which has an equivalent hex understandable by the cpu
Updated 29-Mar-17 21:21pm
Tomas Takac 30-Mar-17 2:36am
Did you read the documentation?
CPallini 30-Mar-17 4:17am
Exactly, my virtual 5.

1 solution

The process of creating an executable program consists of two steps:

  1. Compiling the source files which creates object files
  2. Linking the object files and optional libraries which creates an executable file

This requires two tools: A compiler and a linker.
The GCC is both and the passed command line options specify what should be done.

The -c option tells the GCC to compile the file specified after the option. By default an object file with the same name but the .o extensions will be generated.

The -E and -S options will start compilation but stop at specific processing steps and generate an output file of the appropriate type.

The -o option specifies the output file name and overrides the default (<source-name>.o when compiling, a.out when linking).

Invoking GCC with source file names only is a special case:
It will compile the source files (generate object files), link the object files to create an executable file (a.out), and deletes the object files.

For an overview of all options see Using the GNU Compiler Collection (GCC): Option Summary[^].
CPallini 30-Mar-17 4:17am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900