macro expansion
File inclusion
Conditional compilation
.c or .cpp
.i or .ii
Includes or ignores code blocks based on #ifdef or #ifndef.
Pastes the contents of #include header files (.h / .hpp) directly into the source.
Replaces #define macro to the actual value
Breaks code into tokens (keywords, identifiers, operators).
Builds an Abstract Syntax Tree (AST) to ensure code follows language rules.
Rearranges and streamlines the AST for performance and size.
Converts the optimized tree into architecture-specific Assembly language.
optimization
Code Generation
Lexical Analysis
Syntax Analysis
.a or .asm
Maps variable and function names to memory offsets.
Connects function calls in your code (e.g., printf) to their actual definitions
Assigns final memory addresses to variables and functions across multiple object files.
The Assembler converts mnemonic assembly instructions into raw machine code (binary zeros and ones).
Translation
Symbol Table Creation
Symbol Resolution
Address Binding
.obj or .o
.exe, but standalone..exe): Links against an Import Library (.lib stub) that tells the .exe which .dll to look for later. Builds the Import Address Table (IAT)..so (Shared Object) file to verify symbols exist, building the Procedure Linkage Table (PLT) and Global Offset Table (GOT).Static Linking (.lib Windows / .a Linux):
Dynamic Linking
.exe on win / ELF on Linux
OS loader
Memory Allocation
Windows Loader: Reads the IAT. Finds required .dll (Dynamic Link Library) files on the disk. Maps them into the process's memory space. Updates the IAT with the actual memory addresses of the DLL functions.
Linux Dynamic Linker (ld.so): Finds required .so (Shared Object) files. Loads them into memory. Performs lazy binding (addresses are resolved via PLT/GOT the first time a function is called, saving startup time).
Loading Dynamic libraries
User double-clicks the .exe or runs the binary. The OS reads the executable header.
OS allocates virtual memory for the program's code, data, heap, and stack.
The CPU instruction pointer is set to the executable's entry point (usually _start, which sets up the environment and then calls main()).
When the program hits a library function, it jumps to the memory address where the .dll or .so was mapped during Load Time.
Explicit Runtime Loading (optonal)
Programs can also manually load .dll/.so files mid-execution using APIs like LoadLibrary()/GetProcAddress() (Windows) or dlopen()/dlsym() (Linux) without knowing about them at compile time (used for plugins and mods).