The C/C++ Compilation Model
How a translation unit becomes an object file and why the include graph, not the source line count, determines your build time. Covers the four compilation phases, the One Definition Rule, and the 2026 state of C++20 modules.
Overview
Which phase failed, and what did it see?
Every C and C++ build problem you will be asked to debug reduces to one question: which of the four phases failed, and what did that phase actually see? The gcc or g++ you invoke is not a compiler. It is a driver that inspects file suffixes and chains subprocesses together. Each phase has a flag that stops the driver right after it, so you can look at its output.
- Preprocess (-E) turns hello.cpp plus its headers into a .ii file.
- Compile proper (-S) turns that into assembly, a .s file.
- Assemble (-c) turns the assembly into an object file, a .o.
- Link combines the objects into an executable or a .so.
> [!IMPORTANT] The GCC manual is explicit about this four-stage model. Learn it, because each stage produces errors of a completely different character.
Key concepts
- Translation unit
- The four phases
- One Definition Rule (ODR)
- Declaration versus definition
- Explicit instantiation and extern template
- Pimpl idiom
- Precompiled header (PCH)
- C++20 module and BMI
Interview questions
- Walk me through everything that happens between hello.cpp and a running ./hello.
- What is the One Definition Rule, and how does it actually break in production?
- Why do templates have to live in headers, and what do you do when that is unacceptable?
- Our build takes 40 minutes and touching one header rebuilds 800 files. Walk me through fixing it.
- Where do C++20 modules actually stand in 2026, and would you adopt them?
Sign up free to read the full topic
More DevOps topics
- Terraform & OpenTofu
- Terraform count vs for_each
- Terraform Essentials — Plan and Apply, Variables, Outputs, Data Sources, and Sharing State at Scale
- Terraform in CI/CD Pipelines
- Terraform Remote State — S3 + DynamoDB
- Test Pyramid
- The flux CLI
- The Three Ways
- Toil Reduction & Automation Strategy
- Trunk-Based Development
- Trunk-Based Development with Continuous Deployment
- Twelve-Factor App
Start free on Cariara · Coding problems · System design studio