A C compiler translates a C program written in high-level language into machine-level executable code.
The build process occurs in multiple stages.
The C build process consists of the following steps:
Preprocessing
Compilation
Assembly
Linking
Handled by the preprocessor.
Expands macros (#define)
Includes header files (#include)
Removes comments
Handles conditional compilation
Expanded source file (.i)
Handled by the compiler.
Checks syntax
Converts preprocessed code into assembly code
Performs optimizations
Assembly file (.s)
Handled by the assembler.
Converts assembly code into machine code
Object file (.o)
Handled by the linker.
Links object files
Resolves external symbols
Links standard libraries
Creates final executable
Executable file (a.out / program.exe)
Provide function declarations
Enable compiler to check function usage
| Feature | Static Linking | Dynamic Linking |
|---|---|---|
| Library | Copied into exe | Loaded at runtime |
| Size | Larger | Smaller |
| Speed | Faster | Slightly slower |
Syntax errors
Undeclared variables
Undefined reference
Missing function definitions
gcc – GNU Compiler Collection
make – Build automation
cmake – Build system generator
C compilation occurs in multiple stages
Preprocessor runs first
Compiler generates assembly
Assembler creates object code
Linker produces executable
Take quizzes related to this topic and see where you stand!
Start Quiz Now