📄️ Compilation Pipeline
The C++ compilation process transforms source code into executable binary through four main stages: preprocessing, compilation, assembly, and linking.
📄️ Preprocessing
The preprocessor is a text manipulation tool that runs before compilation. It handles #include, #define, #ifdef, and other directives, producing pure C++ code for the compiler.
📄️ Compilation
The compilation phase translates preprocessed C++ code into assembly language. This is where syntax checking, semantic analysis, optimization, and code generation happen.
📄️ Assembling
The assembler converts human-readable assembly code into binary machine code (object files). Each assembly instruction becomes actual CPU instructions.
📄️ Linking
The linker combines multiple object files and libraries into a single executable, resolving symbol references and assigning final memory addresses.
📄️ Static vs Dynamic
Linking can be static (library code copied into executable) or dynamic (library loaded at runtime). Each has trade-offs in size, deployment, and performance.
📄️ Object Files
Object files (.o, .obj) are compiled but not yet linked binary files containing machine code, data, and metadata for the linker.
📄️ Name Mangling
Name mangling (name decoration) encodes C++ function signatures into unique symbol names for the linker. This enables function overloading and namespaces while maintaining linkage compatibility.
📄️ Translation Units
A translation unit is a single source file plus all its included headers after preprocessing. It's the basic unit of compilation in C++.
📄️ Headers & Includes
Headers (.h, .hpp) contain declarations that are shared across multiple source files. The #include directive copies header contents into source files during preprocessing.
📄️ Include Guards
pragma once
📄️ Build Systems & CMake
Build systems automate compilation, dependency management, and linking. They track changes and rebuild only what's necessary, making large C++ projects manageable.
📄️ Makefiles
Makefiles define rules for building projects using the Make build system. They specify dependencies and commands to compile source code incrementally.
📄️ Cross-Compilation
Cross-compilation builds executables for a different platform (target) than the one running the compiler (host). Essential for embedded systems, mobile development, and deploying to different architectures.