cURL / Mailing Lists / curl-library / Single Mail


Re: setup Issue with libssh2 libcurl and gcc

From: <>
Date: Sat, 21 Jan 2012 21:24:07 +0100

Hiiiaaa, good news from my side. I have it working, I have successfully
compiled my test file :)

Here my compiler string.

$ gcc -Wall -I/usr/include -I/usr/include/libssh2-1.3.0/src test.cpp -o
sftptest -lssh2

$ locate libssh2_config.h

At the end the problem was to use the correct compiler option and to
link against the libssh2 library. Perhaps a good idea to provide this
example compiler string at "". One thing for sure
this will save new adapters of the library a lot of time. The amount of
email thread about this topic is long. And very difficult to find an
answer in these email thread.

An other approvment for the website, please make a search option in the mail overview so that mail can be queried. This
saves a lot of searching over the web.

@Dan thanks for replying my question. without your help I was not able
to get this working. Now the real fun starts :) back to coding


-----Original Message-----
From: <>
Subject: Re: setup Issue with libssh2 libcurl and gcc
Date: Sat, 21 Jan 2012 17:48:09 +0100

Hi Dan, Thanx for providing me some support here. Getting libssh2 to
work is a prerequiset to work with sftp in libcurl so that why I send
this to this email adres. If wrong and not allowed please let me know.

here my next output...

$ gcc -Wall -g -O2 `pkg-config libssh2 --cflags --libs ` -o main
test.cpp:11:28: fatal error: libssh2_config.h: No such file or directory
compilation terminated.

>>Now I have hardcoded full location of libssh2_config.h ( incl path) in
my code file.

$ grep include test.cpp |grep lib
#include <libssh2.h>
#include <libssh2_sftp.h>

>>Now I get another error:

$ gcc -Wall -g -O2 `pkg-config libssh2 --cflags --libs ` -o main
/tmp/ccPGOVgO.o: In function `main':
test.cpp:80: undefined reference to `libssh2_init'
test.cpp:110: undefined reference to `libssh2_session_init_ex'
test.cpp:116: undefined reference to `libssh2_session_set_blocking'
test.cpp:122: undefined reference to `libssh2_session_handshake'
test.cpp:134: undefined reference to `libssh2_hostkey_hash'
test.cpp:144: undefined reference to `libssh2_userauth_password_ex'
test.cpp:215: undefined reference to `libssh2_session_disconnect_ex'
test.cpp:216: undefined reference to `libssh2_session_free'
test.cpp:228: undefined reference to `libssh2_exit'
test.cpp:163: undefined reference to `libssh2_sftp_init'
test.cpp:179: undefined reference to `libssh2_sftp_open_ex'
test.cpp:197: undefined reference to `libssh2_sftp_write'
test.cpp:207: undefined reference to `libssh2_sftp_close_handle'
test.cpp:209: undefined reference to `libssh2_sftp_shutdown'
collect2: ld returned 1 exit status


-----Original Message-----
From: <>
To: libcurl development <>
Subject: Re: setup Issue with libssh2 libcurl and gcc
Date: Sat, 21 Jan 2012 17:16:36 +0100

$ env |grep PKG
$ pkg-config libssh2 --cflags --libs-I/usr/local/include
-L/usr/local/lib -lssh2

-----Original Message-----
From: Dan Fandrich <>
Reply-to: libcurl development <>
Subject: Re: setup Issue with libssh2 libcurl and gcc
Date: Fri, 20 Jan 2012 10:08:36 -0800

On Fri, Jan 20, 2012 at 04:06:43PM +0100, wrote:
> Thanx for helping me out here. Without you help I can make it work.
> Offcource the 'make install' was my mistake in the email, I did this on
> the machie.
> Here the result so far:
> $ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
> $ export PKG_CONFIG_PATH
> $ env |grep PKG
> PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
> $ gcc -Wall -g -O2 `pkg-config libssh2 --cflags --libs` -o main test.cpp
> test.cpp:10:28: fatal error: libssh2_config.h: No such file or directory
> compilation terminated.

Does "pkg-config libssh2 --cflags --libs" produce reasonable output when
run on its own?

> $ locate libssh2_config.h
> /home/itops/Downloads/linssh2/libssh2-1.3.0/example/libssh2_config.h
> /home/itops/Downloads/linssh2/libssh2-1.3.0/example/
> /home/itops/Downloads/linssh2/libssh2-1.3.0/src/libssh2_config.h
> /home/itops/Downloads/linssh2/libssh2-1.3.0/src/
> /home/itops/Downloads/linssh2/libssh2-1.3.0/vms/libssh2_config.h
> /home/itops/Downloads/linssh2/libssh2-1.3.0/win32/libssh2_config.h
> I think here that the default location is not correct, but how to solve
> this one.

The libssh2_config.h file is private and shouldn't be used outside of
libssh2 itself. However, it looks to me like the example programs are
"cheating" in that they are actually using that private file. It makes
some sense in this case because the examples really are part of libssh2,
and it's very convenient to use that internal file since it allows the
example code to stay rather more clean and simple and still portable
across a number of machines. But real applications should be configuring
themselves properly without using that file.

If you just want to get the example going, just copy libssh2_config.h from
your libssh2 build directory into the same directory as your example
source file. But when you build your actual app out of that example code
(if you do it that way), then remove the use of that file and either
hard-code the correct configuration for your desired platform in the
source, or use something like autoconf to configure your application

>>> Dan
List admin:

List admin:
Received on 2012-01-21