C++ › Compilation & Linking

What causes an 'undefined reference' (unresolved symbol) linker error?

Beginner

Answer

It means a symbol was declared and used but the linker couldn't find its definition: a missing source file/object, a library not linked, a function declared but never defined, a signature mismatch (name mangling differs), or forgetting extern "C" for C functions. The fix is to provide/link the definition or correct the declaration.
// declared void f(); used f(); but f never defined -> undefined reference
Real-world example Forgetting to link the math library or a .cpp file yields an 'undefined reference' at link time.

Common follow-ups: What are common causes? | Is it a compiler or linker error?