SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
C++ 11 errors

C & C++ Errors

Segfaults, linker errors, memory corruption and template deduction failures.

Understanding C++ errors

C++ errors fall into two very different worlds. Compile and link errors (undefined reference, multiple definition, template substitution failure) are deterministic and are almost always about declarations, the One Definition Rule, or link order. Runtime memory errors (segfaults, double free, use-after-free) are non-deterministic and should never be debugged by reading code alone; a sanitizer will find in seconds what code review misses for days.

How to debug C++ errors

  1. Rebuild with sanitizers before anything else: -fsanitize=address,undefined -fno-omit-frame-pointer -g. AddressSanitizer reports the exact allocation and free sites for use-after-free and double-free.
  2. For undefined-reference errors, check link order, remembering that with GNU ld libraries must come after the objects that use them, and check for a C/C++ linkage mismatch that needs extern "C".
  3. Use nm -C libfoo.a | grep symbol to confirm the symbol is actually present and to see the demangled signature. A signature that differs by a const is a different symbol.
  4. Enable core dumps (ulimit -c unlimited) and open them in gdb with gdb ./binary core, then bt full. A stack trace beats speculation.
  5. For template errors, read the message from the bottom up. The final line is usually the real constraint that failed; everything above is instantiation context.

Tools worth reaching for

  • -fsanitize=address,undefined
  • valgrind
  • gdb / lldb
  • nm -C
  • ldd

All 11 C++ errors

Other categories