Skip to content
Latchkey

ld "undefined reference to std::__throw_*" (libstdc++ version) in CI

libstdc++ internal helpers like std::__throw_length_error exist only from a given libstdc++ version. Linking objects built against a newer libstdc++ to an older one leaves those symbols undefined.

What this error means

Linking fails with "undefined reference to std::__throw_..." (or similar internal symbols) when build and link libstdc++ versions differ.

ld
/usr/bin/ld: main.o: undefined reference to
'std::__throw_bad_array_new_length()'
collect2: error: ld returned 1 exit status

Common causes

How to fix it

Align the libstdc++ versions

  1. Compile and link with the same GCC/libstdc++ toolchain.
  2. Upgrade the runtime libstdc++ to at least the build version.
ld
strings $(g++ -print-file-name=libstdc++.so) | grep GLIBCXX | tail

How to prevent it

  • Build and link with a single, pinned GCC/libstdc++ toolchain so internal symbols requested by your objects always exist in the runtime library.

Frequently asked questions

What causes ""undefined reference to std::__throw""?
Linking fails with "undefined reference to std::__throw_..." (or similar internal symbols) when build and link libstdc++ versions differ.
How do I fix "undefined reference to std::__throw"?
Align the libstdc++ versions

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card