Safe to link to static libstdc++ from shared library?
Fredrik Orderud
forderud@gmail.com
Fri Nov 14 15:31:27 GMT 2025
> > We're already building our shared library in an old Linux container
> > with glibc 2.27 and libstdc++ 20191114 for improved backwards
>
> I don't know what libstdc++ 20191114 is. Presumably the value of
> __GLIBCXX__ but that's not meaningful, see the discussion of
> __GLIBCXX__ at https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning.history
> (and the suggestion to use _GLIBCXX_RELEASE instead).
Thanks' for the suggestion! Just checked, and we're using libstdc++ 7
in the docker build image.
> > compatibility. However, it then becomes a tension between the oldest
> > libstdc++ version supported and the newest C++ version supported. We
> > basically want to adopt C++23 and newer internally in our shared lib
> > while still being compatible with old systems. My hope was that static
> > linking to libstdc++ could help eliminate that problem.
>
> That's unlikely to work, because the C++23 ABI is not stable yet. You
> can't mix and match any objects compiled with C++23 mode by different
> GCC versions, because the C++23 features like std::expected might not
> be ABI compatible between GCC 13 and GCC 14, for instance.
I might be colored by my Windows background here, but I though that
C++ ABI compatibility isn't a problem as long as our shared library
only uses C++ _internally_, while the API i in pure "C" with no
exceptions escaping. However, I might have been naive here(?)
More information about the Libstdc++
mailing list