Understanding C++ linking and compilation in a multi-file project
This is a medium-difficulty C++ question that tests your grasp of how the compiler and linker handle symbols across translation units. Rather than asking you to write code, it asks you to predict the behaviour of a complete program—a skill essential for debugging in larger codebases and understanding when compilation succeeds or fails.
To answer correctly, you need to reason about scope, linkage, and symbol resolution. Key considerations include whether functions or variables are declared versus defined, how internal and external linkage work, and whether the linker can find all required symbols when combining object files. The question rewards careful reading of the actual code and a precise mental model of the separate compilation and linking phases.
- Translation units and the preprocessing/compilation/linking pipeline
- Internal vs. external linkage and the
static and inline keywords - Forward declarations and symbol resolution
- Common linker errors and when they occur