Static linking to libgcc_s and libstdc++

Rupert Wood me@rupey.net
Mon Aug 5 06:24:00 GMT 2002


John Carter wrote:

> Alas, it expects a sharable libstdc++ and libgcc_s.
:
> How can I convince gcc to statically link in those libraries
> (and no other sharable libraries)?

I'm on shaky ground here - I'm no ld expert - but:

   gcc <objects> -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic <rest of libs>

This should work with GNU ld but I've only tried it using Solaris ld.

Note that you're explicitly breaking GCC's C++ model object model: all
C++ binaries and shared libraries link in libgcc_s so that they all use
the same binary copy of the exception handling mechanism. If, however,
all C++ code is in your executable and all dynamic libraries are plain C
then you should get away with linking these statically.

Since you have to link libstdc++ explicitly yourself, you should use the
gcc driver and not the g++ driver. Combined with linking it before any
other libraries, this should enforce the plain-C-libraries-only
requirement at link time.

Good luck,
Rup.



More information about the Gcc-help mailing list