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 statusCommon causes
How to fix it
Align the libstdc++ versions
- Compile and link with the same GCC/libstdc++ toolchain.
- Upgrade the runtime libstdc++ to at least the build version.
ld
strings $(g++ -print-file-name=libstdc++.so) | grep GLIBCXX | tailHow 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
ld "undefined reference to std::filesystem" (needs -lstdc++fs) in CIFix ld "undefined reference to std::filesystem" in CI - older GCC/Clang ship filesystem in a separate library…
ld "undefined reference to SSL_*" (OpenSSL link order) in CIFix ld "undefined reference to SSL_new / EVP_*" in CI - OpenSSL is missing or listed before the objects that…
ld "undefined reference to pthread_create" (missing -pthread) in CIFix ld "undefined reference to pthread_create" in CI - threading code linked without -pthread, so the POSIX t…