GCC / Clang Linker Error: undefined reference to `symbol`
Object file declared a function in a header but failed to link the library or placed `-lfoo` before `.o` files.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: GCC / Clang Linker Error
Platform: C/C++
Common Root Causes:
- Object file declared a function in a header but failed to link the library or placed `-lfoo` before `.o` files.
Interactive Diagnostic Checklist
Verified Solutions:
- Pass libraries (`-lm`, `-lpthread`, `-lssl`) AFTER source/object files in link order.
Safe Diagnostic Command:
nm -C <lib.a> | grep <symbol>
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Object file declared a function in a header but failed to link the library or placed `-lfoo` before `.o` files. Recommended diagnostic: `nm -C <lib.a> | grep <symbol>`. Remediation: Pass libraries (`-lm`, `-lpthread`, `-lssl`) AFTER source/object files in link order.
Worked Examples
- Run `nm -C <lib.a> | grep <symbol>` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-cpp-undefined-reference-linker · Independently verified: 2026-11-25