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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →