[nSLUG] Static Linking Question C++

Jon Watson me at jonwatson.ca
Sat May 31 13:26:56 ADT 2008


On Sat, May 31, 2008 at 12:47 PM, Aaron Spanik <a.spanik at ns.sympatico.ca>

> On Sat, 31 May 2008 10:44:35 -0300
> "Jon Watson" <me at jonwatson.ca> wrote:
> > Hi All,
> >
> > While this is a programming question and not specifically a Linux
> question,
> > I think it's close enough to be in scope.
> Interesting how the definition of "on-topic" seems to vary according
> to "need".

True indeed. I guess  I was just trying to give a nod to the fact that I am
aware this is a programming question in general and not specific to Linux.

> (you can't reduce that command; but you can create a Makefile to
> generate the appropriate command(s) for you)

Yeeees, in my attempts to figure this out for myself I've run across that
idea and it makes sense.

> "Extensive Googling" didn't get you this?
> http://www.trilithium.com/johan/2005/06/static-libstdc/
> (the extensive Googling I did to get that amounted to "linux c++
> statically compiled"[1])

It did indeed but as I stated in my original post, this problem (for me) is
in the "never-even-knew-that" territory. I guess that's not really clear,
but what it means is that this subject matter is so new to me that I don't
even know what I don't know. Hence, that post (and a lot of other stuff I
ran across) were over my head. I have a better grip now on the theory behind
static linking, but not the experience to suss the proper syntax to make it

> You can't mix dynamic and static C++ code.  You can, however,
> dynamically link the C portions whilst statically linking the C++. The
> list of libraries above says you've got libstdc++ included, for
> obvious reasons.
> According to the link provided above, for each of the C++ libraries,
> you'll want to do something like:
> $ ln -s `g++ -print-file-name=libstdc++.a`
> This will create a link to libstdc++.a in the current directory.
> You then change your compile command to look first in the current
> directory for libraries by adding "-L." to your g++ command:
> $ g++ -static -static-libgcc -L. -L<other libdirs> -o foo foo.cpp \
>     src/crypt.cpp src/ne7ssh_channel.cpp \
>    src/ne7ssh_connection.cpp src/ne7ssh_error.cpp \
>    src/ne7ssh_kex.cpp src/ne7ssh_keys.cpp src/ne7ssh_mutex.cpp \
>    src/ne7ssh.cpp src/ne7ssh_session.cpp src/ne7ssh_string.cpp \
>    src/ne7ssh_transport.cpp src/ne7ssh_sftp.cpp \
>    src/ne7ssh_sftp_packet.cpp
> You probably don't need to use "-lbotan" in this case because it will
> be found in the current directory.
> You probably need to also look into using -static-libgcc.

That was remarkably helpful, thank you. I will give this a whirl when I get
back to my system.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/mailman/private/nslug/attachments/20080531/7af7e37d/attachment.html>

More information about the nSLUG mailing list