The linker cannot find the implementation for a declared function or variable.
A linker error (such as `ld returned 1 exit status` or `undefined reference to foo()`) occurs after compilation succeeds when the linker tries to resolve function calls to compiled object files/libraries but cannot find the function definition.
Declaring a function prototype in a header `.h` file without defining its body in a `.cpp` file, forgetting to link an object file or library (`-lfoo`), or missing `main()` entrypoint.
1// math_utils.h2void compute();3 4// main.cpp5#include "math_utils.h"6 7int main() {8 compute(); // Linker error: undefined reference to 'compute()'9 return 0;10}1// math_utils.cpp2#include <iostream>3#include "math_utils.h"4 5void compute() {6 std::cout << "Computation complete" << std::endl;7}8 9// Build command linking both files:10// g++ main.cpp math_utils.cpp -o appSimulate standard system builds to trigger compiler trace records and track memory crashes locally.
The header declares `compute()`, allowing `main.cpp` to compile into an object file (`main.o`). However, during the linking phase, `compute()` has no compiled function body in any `.cpp` file.