What happens when you type gcc main.c

Yunis Gulamov
1 min readJun 18, 2024

--

First of all gcc is an alias that reflects commands.There have some processes in gcc command.Lets specify them:

1. Preprocessing:

• The preprocessor reads main.c, processes any preprocessor directives, and outputs preprocessed code.

2. Compilation:

• The compiler translates the preprocessed code into assembly language and outputs an assembly file.

3. Assembly:

• The assembler converts the assembly language code into machine code, resulting in an object file.

4. Linking:

• The linker combines main.o with any necessary libraries and produces the final executable.

Lets specify this things on code example:

Preprocessing: main.c -> main.i

  • gcc -E main.c -o main.i

Compilation: main.i -> main.s

  • gcc -S main.c -o main.s

Assembly: main.s -> main.o

  • gcc -c main.c -o main.o

Linking: main.o -> a.out

  • gcc main.c -o my_program

The -o option allows us to specify a different name for the output executable.

And finally if we want run our executable program, we must type:

./my_program

In there “./my_program” is the “-o my_program”

This article ends here and finally I want to say that this is my first article. I hope you like it.

--

--