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.
Preprocessor ā Compiler ā Assembler ā Linker ā Executable.
main.cpp
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
ā¢
ā¢
ā¢
The preprocessor never sees types or logic ā it is pure text manipulation.
#:ā¢
#include ā pastes the entire header file content inlineā¢
#define ā does text substitution (replaces every PI with 3.14159)ā¢
#ifdef / #endif ā conditionally includes blocks of codeThe preprocessor never sees types or logic ā it is pure text manipulation.
main.cpp
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.
⢠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
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.
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
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
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.
AI Tutor
Understanding compilation helps you debug linker errors vs compiler errors, and understand how header files work.