Advertisement
Beginner C++, Compilation & Linking

What are the stages of building a C++ program?

Short answer

Building involves: preprocessing (handling #include/#define to produce a translation unit), compilation (translating each translation unit to an object file, checking syntax and types), and linking (combining object files and libraries, resolving symbol references, into an…

Save C++ mock interview
Advertisement
AModel answer
Building involves: preprocessing (handling #include/#define to produce a translation unit), compilation (translating each translation unit to an object file, checking syntax and types), and linking (combining object files and libraries, resolving symbol references, into an executable or library). Understanding the stages helps diagnose where an error (preprocessor, compiler, or linker) occurs.
Example

g++ -E file.cpp # preprocess g++ -c file.cpp # compile to file.o g++ file.o -o app # link

Real-world example
A 'undefined reference' error is a linker error, not a compiler error—knowing the stages pinpoints the fix.
Likely follow-ups
  • What are the three main stages? | Which stage resolves symbols?
Related topics