Subject: Re: static linking problem

Re: static linking problem

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 18 Oct 2010 16:43:38 -0700

On Tue, Oct 19, 2010 at 12:08:51AM +0100, may nothing wrote:
> >The order of arguments makes a difference. Try this order:
>
> >gcc -Wall -I/usr/include -I/usr/local/include -static sftptest.c -o sftptest
> >/usr/local/lib/libssh2.a
> >
>
> >and since you have already have -static there, this ought to work, too:
>
> >gcc -Wall -I/usr/include -I/usr/local/include -static sftptest.c -o sftptest
> >-lssh2
>
> >>>> Dan
>
> Hi,
>
> sorry but that's even worse. It produces:

That's actually *better*. It means that it's finally trying to link with
libssh2 statically.

> also adding -lssl has no impact.
> Using gcc 4.4 (32-Bit) on Suse 11.0

You need to add all the libraries given by "pkg-config libssh2 --static
--libs". If that command doesn't give you anything, then your libssh2
installation is broken. That command should give you at least -lssl
and -lcrypto if your libssh2 uses OpenSSL.

> Another point is, when I do dynamical linking like: 'gcc -o sftptest sftptest.c
> -lssh2' everything works fine ...
> But in this case I need the statical linked version since the target box doesn't
> have the libraries needed to run the binary.

Yes, because the dynamic libraries include all the dependencies themselves.
When you link statically, without libtool, you need to provide them yourself.
pkg-config is the easiest way to get them.

>>> Dan
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-10-19