A strong answer
A compiler error happens during phase 2 of the build pipeline (cc1), when the compiler analyzes a single translation unit (.c file after preprocessing) in isolation. It is caused by violations of C grammar or type rules inside that file—such as a missing semicolon, an undeclared identifier, or passing incompatible argument types to a declared function. Compiler diagnostics always name a .c or .h source file, a line number, and a column number.
A linker error happens during phase 4 (ld), after every .c file has already compiled cleanly into a relocatable .o object file. When code calls a function declared via a prototype (such as double compute(double x);), the compiler trusts the promise and emits a call instruction with a placeholder relocation entry. The linker must connect that relocation to the single object file or library that defines compute. Linker errors fall into two main categories: undefined reference (no object file or linked library provides the definition, or main itself is missing) and multiple definition (two or more object files define the same external symbol, violating the One Definition Rule).
What the interviewer is listening for
- Knows that the compiler checks one translation unit at a time using declarations/prototypes, while the linker resolves symbols across all
.ofiles and libraries. - Recognizes
undefined reference to 'foo'andmultiple definition of 'bar'as linker (ld) diagnostics. - Explains how missing
-l<lib>flags or uncompiled.cfiles cause undefined references even when the right#includeheader is present.
Common mistakes
- Re-editing header
#includelines to fix anundefined referenceerror when the header was already included and the real fix is linking the.cor-llibrary. - Putting function or global variable definitions (without
staticorinline) inside a.hheader file included by multiple.cfiles, causing a multiple-definition linker error. - Confusing compile-time header search paths (
-I) with link-time library search paths (-Land-l).