The process of C compilation

Julian
1 min readJun 18, 2021

Phase 1: Pre-processing:

When the compilation of a C program begins, it starts with the pre-processing. The compiler begins by reading the contents of the header and inserts it into the program text. The header and defined macros are expanded and merged within the file and produces a transitory file.

Phase 2: Compilation:

In this phase, the pre-processed data is taken as input, compiled and produced as a temporary compiled file. Assembly code is produced and passes on to the next phase.

Phase 3: Assembly

In this phase, the assembler converts assembly code to binary code. The assembler calls to external functions and leaves them undefined.

Phase 4: Linking

Linking is the final phase of compilation. It links the object files to create a finished compiled file.

Examples:

Command to compile: gcc <filename>

Command options:

  • -c Option to compile and assemble the file, but not link.
  • -S Option to not assemble, and replace file extension suffix with .s
  • -E Option to stop after the pre-processing phase.
  • -o Option to place an output in another file.

--

--

Julian
0 Followers

I don’t know if I’ve found it, I just know it makes me happy.