tags:

views:

177

answers:

2

So I am trying to compile the libssh2 library on linux, but when I try to compile the example it comes up with a lot of errors, and even though I include the headerfile it asks for, it still asks for it. Here are the error messages and the resulting messages:

~/ gcc -include /home/Roosevelt/libssh2-1.2.5/src/libssh2_config.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c
/home/Roosevelt/libssh2-1.2.5/example/scp.c:7:28: error: libssh2_config.h: No such file or directory
/home/Roosevelt/libssh2-1.2.5/example/scp.c: In function 'main':
/home/Roosevelt/libssh2-1.2.5/example/scp.c:39: error: storage size of 'sin' isn't known
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'AF_INET' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: (Each undeclared identifier is reported only once
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: for each function it appears in.)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:81: error: 'SOCK_STREAM' undeclared (first use in this function)
/home/Roosevelt/libssh2-1.2.5/example/scp.c:87: error: invalid application of 'sizeof' to incomplete type 'struct sockaddr_in'

Here is the new errors:

scp.c:(.text+0x106): undefined reference to `libssh2_init'
scp.c:(.text+0x1fe): undefined reference to `libssh2_session_init_ex'
scp.c:(.text+0x234): undefined reference to `libssh2_session_startup'
scp.c:(.text+0x288): undefined reference to `libssh2_hostkey_hash'
scp.c:(.text+0x36f): undefined reference to `libssh2_userauth_password_ex'
scp.c:(.text+0x3e7): undefined reference to `libssh2_userauth_publickey_fromfile_ex'
scp.c:(.text+0x437): undefined reference to `libssh2_scp_recv'
scp.c:(.text+0x531): undefined reference to `libssh2_channel_read_ex'
scp.c:(.text+0x5f8): undefined reference to `libssh2_channel_free'
scp.c:(.text+0x628): undefined reference to `libssh2_session_disconnect_ex'
scp.c:(.text+0x636): undefined reference to `libssh2_session_free'
scp.c:(.text+0x66e): undefined reference to `libssh2_exit'
collect2: ld returned 1 exit status
+2  A: 

The header file is not included: libssh2_config.h

There is an inclusion directive in the source code, so you have to indicate the path to the header with the -I option: gcc -I/home/Roosevelt/libssh2-1.2.5/src

The -include option shall be used to include a header file which is not explicitly included in the source code with a #include directive.

philippe
That really helped on getting it to do what I wanted, thanks.Is there a way to add multiple directories?
Kris
@Kris, yes you can have several -I options on the command line. They will all be added to the list of directories that are searched.
philippe
Okay, so I successfully compiled the code, but when I try to compile an example script, I still pretty much get the same errors.The really odd thing is, that if I remove my include, I still get the same errors. I added the new errors to the top of the page.
Kris
@Kris: this is now a link edition problem. What is the command that leads to this new error message ?You probably need to add something along the lines of '-L<the name of the dir where the ssh2 lib is> -lssh2'.
philippe
I used this command:~$ gcc -include /home/Roosevelt/libssh2-1.2.5/include/libssh2.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c
Kris
@Kris: your executable needs to be linked with the libssh2 library. You need to indicate that ( -lssh2) as well as the path where the library file (libssh2.a or libssh2.so) is ( -L<path> ). Try with :gcc -include /home/Roosevelt/libssh2-1.2.5/include/libssh2.h -o lolbaise /home/Roosevelt/libssh2-1.2.5/example/scp.c -L/home/Roosevelt/libssh2-1.2.5/lib -lssh2
philippe
Now I only get 2 errors:scp.c:(.text+0xfb): undefined reference to `libssh2_init'scp.c:(.text+0x5bd): undefined reference to `libssh2_exit'Apparently only -lssh2 is required for it to not turn out that horde of errors, the -L command is kind of redundant.
Kris
I take it this is because -lssh2 refers to the native built in library?
Kris
+1  A: 

I just cloned the current git build and went into the 1.2.5 relase but I'm unable to reproduce your problem.

./buildconf
/.configure
make

works fine. What are you trying to do exactly?

pmr
typofix: the second line should be `./configure` of course
ShinTakezou
C++ is kinda new to me, so I was unsure if I needed to compile it first, thanks.
Kris