C++ Project Structure
Why This Series Exists
Writing a C++ program from scratch is not only about syntax. You also need to know where files go, what belongs in headers, what belongs in .cpp files, how declarations and definitions connect, what the compiler produces, and why the linker fails with errors like "undefined reference" or "multiple definition".
This series treats those topics as project-management fundamentals. The C++ language series can focus on language features, while this From Scratch series explains how real C++ projects are physically organized and built.
The Mental Model
If you understand those five lines, most C++ build errors become much easier to debug.
Recommended Reading Order
1. Project Layout
How to structure folders for source files, headers, tests, examples, assets, and build output.
2. Header Files
How headers are created, what declarations belong inside them, and how include guards work.
3. Source Files
How .cpp files include headers, provide definitions, and interact with other translation units.
4. Compiler
Preprocessing, translation units, parsing, optimization, assembly, and object files.
5. Linker
Symbol resolution, static and dynamic libraries, undefined references, and multiple definitions.
6. One Definition Rule
Why definitions must be organized carefully across headers and source files.
7. Build Systems
Why Make, Ninja, CMake, package managers, and compilation databases exist.
8. CMake
A practical CMake guide with command explanations, custom targets, and a LibTorch example.