C Compiler and Build Process

📘 C 👁 35 views 📅 Dec 22, 2025
⏱ Estimated reading time: 2 min

A C compiler translates a C program written in high-level language into machine-level executable code.
The build process occurs in multiple stages.


Phases of C Compilation

The C build process consists of the following steps:

  1. Preprocessing

  2. Compilation

  3. Assembly

  4. Linking


1. Preprocessing

Handled by the preprocessor.

Tasks:

  • Expands macros (#define)

  • Includes header files (#include)

  • Removes comments

  • Handles conditional compilation

Output:

  • Expanded source file (.i)

gcc -E program.c > program.i

2. Compilation

Handled by the compiler.

Tasks:

  • Checks syntax

  • Converts preprocessed code into assembly code

  • Performs optimizations

Output:

  • Assembly file (.s)

gcc -S program.i

3. Assembly

Handled by the assembler.

Tasks:

  • Converts assembly code into machine code

Output:

  • Object file (.o)

gcc -c program.s

4. Linking

Handled by the linker.

Tasks:

  • Links object files

  • Resolves external symbols

  • Links standard libraries

  • Creates final executable

Output:

  • Executable file (a.out / program.exe)

gcc program.o -o program

Complete Build Command

gcc program.c -o program

Role of Header Files

  • Provide function declarations

  • Enable compiler to check function usage

#include

Static vs Dynamic Linking

FeatureStatic LinkingDynamic Linking
LibraryCopied into exeLoaded at runtime
SizeLargerSmaller
SpeedFasterSlightly slower

Compiler Errors vs Linker Errors

Compiler Errors

  • Syntax errors

  • Undeclared variables

Linker Errors

  • Undefined reference

  • Missing function definitions


Build Tools

  • gcc – GNU Compiler Collection

  • make – Build automation

  • cmake – Build system generator


Summary

  • C compilation occurs in multiple stages

  • Preprocessor runs first

  • Compiler generates assembly

  • Assembler creates object code

  • Linker produces executable


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes