C++ › Compilation & Linking

What is a translation unit?

Beginner

Answer

A translation unit is a single source file after preprocessing—the .cpp file with all its #included headers textually expanded. The compiler processes one translation unit at a time into an object file. Concepts like internal linkage and the one-definition rule are defined in terms of translation units.
Real-world example Each .cpp plus its expanded headers is one translation unit compiled independently into a .o file.

Common follow-ups: What does the compiler do per translation unit? | How do headers relate to it?