This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Gcc static linking problems
- From: "Meng-Hsueh Chiang" <mhchiang at mail dot com>
- To: "Tim Purkerson" <timp at apcon dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 11 Aug 2003 22:11:06 -0500
- Subject: Re: Gcc static linking problems
> If I use the exact source code and makefile everything works great
> except it builds the application to use dynamic linking. This becomes a
> problem when our customer's systems don't have the libraries this
> application needs (libstdc++ specifically).
>
> So, the obvious solution is to build it statically, but I can't get it
> to build. There are error messages about unresolved externals that
> should be resolved in the libsocket library.
>
>
> 2. I have seen a lot of posts about adding -static to the build line and
> even alternating static and dynamic to get it to build correctly. I have
> tried many combination of this with no success. What am I doing wrong on
> this line?
> g++ -lnsl -lsocket program.o -o program -static -lstdc++
>
Can you try
g++ -o program program.o -Bstatic -lstdc++ -Bdynamic -lsocket -lnsl
(The order is important as Claudio said in earlier reply)
I guess the default is dynamic, so you'd need to add -dynamic after
-static assuming you only want to link -lstdc++ statically and others
dynamically. Can you also check your .cshrc(?) and make sure there is
no LD_OPTIONS set. Hope it helps.
Meng