Steps of compilation

Marcelo Arbiza
2 min readJun 17, 2021

C Language

The first step we need to know is whats is C.

C is a procedural programming language, developed by Dennis Ritchie in 1972. It was mainly developed as a system programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development.

Four Steps of Compilation: preprocessing, compiling, assembly, linking.

Preprocessing

Here the preprocessor look for all the lines starting with # and obey them (with some actions spicified by the directive).

  • removes comments from the source code.
  • expanding macros
  • expanding included files

The preprocessing of a C file generates a .i extension file.

How we do this?

gcc -E file.c

This file will be taken for the nextstep.

Compiling

Here the comiler takes the .i file generated in the previous step (Preprocessing) and translates the file into assembly language and checks the C language syntax for errors.

The compiling generates a .s extension file.

How we do this?

gcc -S file.c

Assembly

Last step!…almost. Here the assembler takes the .i file and transforms it into a object code, machine language (binary).

The assembly generates a .o extension file.

How we do this?

gcc -c file.c

Linking

The linking stage takes produces a binary executable program.

2 requirements:

  • The implementations for any functions referenced in any part of the code have been defined
  • there is exactly one main function defined

1, 2, 3, 4…FINISH!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Marcelo Arbiza
Marcelo Arbiza

No responses yet

Write a response