Safe to link to static libstdc++ from shared library?

Fredrik Orderud forderud@gmail.com
Fri Nov 14 13:44:41 GMT 2025


I'm working on a project developing a Linux shared library (.so) with
a pure "C" interface that we want to be as widely compatible as
possible with multiple distros of various age. The -static-libstdc++
option therefore seemed attractive, since it appear to eliminate
run-time dependencies to libstdc++. We've therefore used
-static-libstdc++ together with -Wl,--exclude-libs,ALL in an attempt
to encapsulate all C++ dependencies (and other 3rd party libraries),
so that callers doesn't need to know about the C++ stuff inside the
shared library.

This worked fine for a while, but now we suddenly started experiencing
segmentation faults when calling std::async from the shared lib. I'm
not sure if this is a caused by a bug, a known limitation or our
misunderstanding of the libstdc++ documentation. A minimal reproducer
is available on
https://github.com/forderud/UnixSharedLib/tree/main/static-libstdc%2B%2B

ASK: Are there any documented or undocumented limitations on
-static-libstdc++ usage when building shared libraries on Linux?

Thanks in advance,
Fredrik


More information about the Libstdc++ mailing list