This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Static linking to libgcc_s and libstdc++
- From: "Rupert Wood" <me at rupey dot net>
- To: "'John Carter'" <john dot carter at tait dot co dot nz>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 5 Aug 2002 14:23:59 +0100
- Subject: RE: Static linking to libgcc_s and libstdc++
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.