CurriculumCompilation Process

Compilation Process

C++ is a compiled language. Unlike interpreted languages (like Python or JavaScript), C++ source code must go through several distinct steps to become a runnable program.

01The Full Pipeline

When you click Run, watch the pipeline animate. Your .cpp file travels through 5 stages before becoming a program.

Preprocessor → Compiler → Assembler → Linker → Executable.
main.cpp
Loading...
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out

Run the code to animate the pipeline.

02Stage 1 — The Preprocessor

The preprocessor runs before the compiler. It handles all lines starting with #:

• #include — pastes the entire header file content inline
• #define — does text substitution (replaces every PI with 3.14159)
• #ifdef / #endif — conditionally includes blocks of code

The preprocessor never sees types or logic — it is pure text manipulation.
main.cpp
Loading...
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out

Run the code to animate the pipeline.

03Stage 2 — The Compiler

The compiler reads your C++ and checks it for correctness — types, syntax, undeclared variables — then translates it to assembly language.

• A missing semicolon → compiler error
• A wrong type (e.g. passing a string where int is expected) → compiler error
• An undeclared variable → compiler error

Try editing the code to create a mistake and see the error message.
main.cpp
Loading...
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out

Run the code to animate the pipeline.

04Stage 3 — Object Files & the Linker

Large projects have many .cpp files. Each is compiled to an object file (.o) independently. The Linker combines all object files into the final executable.

A linker error looks like: undefined reference to foo. This means you declared a function but never defined it. The compiler was happy, but the linker could not find the implementation.
main.cpp
Loading...
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out

Run the code to animate the pipeline.

05Stage 4 — Header Files in Practice

Professional C++ projects split code into header files (.h) and source files (.cpp):

• .h — declarations (what exists)
• .cpp — definitions (what it does)

#include "math.h" pastes the declarations so the compiler knows about them, and the linker connects the implementations at link time.
main.cpp
Loading...
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out

Run the code to animate the pipeline.

← Back to Curriculum