LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-14-2012, 01:42 PM   #1
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Rep: Reputation: 2
libssh2 compile issue


Took this code from libssh2 project website.

Code:
[me@horse ssh2]$ cat test.c 
#include<stdio.h>
#include <libssh2.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>

static int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
{
    struct timeval timeout;
    int rc;
    fd_set fd;
    fd_set *writefd = NULL;
    fd_set *readfd = NULL;
    int dir;
 
    timeout.tv_sec = 10;
    timeout.tv_usec = 0;
 
    FD_ZERO(&fd);
 
    FD_SET(socket_fd, &fd);
 
    /* now make sure we wait in the correct direction */ 
    dir = libssh2_session_block_directions(session);

 
    if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
        readfd = &fd;
 
    if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
        writefd = &fd;
 
    rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
 
    return rc;
}


main(){
	printf ("at the end \n");

}
Code:

Compiling it bring the error as "libssh2_session_block_direction" does not exist. [me@horse ssh2]$ gcc -o test test.c /tmp/ccwC6mej.o: In function `waitsocket': test.c:(.text+0x91): undefined reference to `libssh2_session_block_directions' collect2: ld returned 1 exit status [me@horse ssh2]$

But it does exist in the header file libssh2.h
Code:
[me@horse ssh2]$ grep -i2  libssh2_session_block_directions /usr/include/libssh2.h 
                                           int *errmsg_len, int want_buf);
LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);

LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
[me@horse ssh2]$


My versions of ssh and co.

Code:
[me@horse ssh2]$ rpm -aq | grep ssh
libssh2-1.2.7-4.fc16.i686
openssh-5.8p2-25.fc16.i686
libssh2-devel-1.2.7-4.fc16.i686
openssh-server-5.8p2-25.fc16.i686
openssh-askpass-5.8p2-25.fc16.i686
openssh-clients-5.8p2-25.fc16.i686
[me@horse ssh2]$

Last edited by PoleStar; 12-14-2012 at 01:46 PM.
 
Old 12-16-2012, 04:22 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
$ rpm -ql libssh2-devel
/usr/include/libssh2.h
/usr/include/libssh2_publickey.h
/usr/include/libssh2_sftp.h
etc.

If you have no /usr/include/libssh2.h, please reinstall :

# yum install --reinstall libssh2-devel


.
 
Old 12-17-2012, 10:04 AM   #3
PoleStar
Member
 
Registered: Jul 2010
Posts: 231

Original Poster
Rep: Reputation: 2
Thanks.

Its still the same.


Code:
Installing : libssh2-devel-1.2.7-4.fc16.i686                                                 1/1 
  Verifying  : libssh2-devel-1.2.7-4.fc16.i686                                                 1/1 

Installed:
  libssh2-devel.i686 0:1.2.7-4.fc16                                                                

Complete!
[me@horse ~]$ rpm -ql libssh2-devel
/usr/include/libssh2.h
/usr/include/libssh2_publickey.h
/usr/include/libssh2_sftp.h
/usr/lib/libssh2.so
/usr/lib/pkgconfig/libssh2.pc
/usr/share/doc/libssh2-devel-1.2.7
/usr/share/doc/libssh2-devel-1.2.7/COPYING
[me@horse ~]$ 
[me@horse ~]$
Code:
[me@horse ssh2]$ gcc -o test  test.c 
/tmp/cc2uJ7xL.o: In function `waitsocket':
test.c:(.text+0x91): undefined reference to `libssh2_session_block_directions'
collect2: ld returned 1 exit status
[me@horse ssh2]$
Code:
me@horse ssh2]$ ls -l  /usr/include/libssh2.h
-rw-r--r--. 1 root root 45303 Aug 17  2010 /usr/include/libssh2.h
[me@horse ssh2]$ ls -l  /usr/include/libssh2.h
 
Old 12-17-2012, 10:43 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by PoleStar View Post
But it does exist in the header file libssh2.h
A C library generally provides 2 things: the declarations (in the header files) and the definitions (in the library file, .a for static libraries, .so for shared libraries). To tell the linker to use the library file you use -lfoo which tells the linker to look for libfoo.a or libfoo.so, in your case to get libssh2.so you pass -lssh2:
Code:
gcc -o test  test.c -lssh2
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
libssh2 script 128 Programming 1 11-18-2012 10:51 PM
trouble compiling libssh2 tincboy Linux - Software 1 06-18-2010 12:32 PM
libssh2 extension bluepepsi Linux - Server 1 05-22-2010 04:15 AM
libssh2 ver. 0.18 RaduH Linux - General 2 11-29-2007 09:59 AM
Libssh2 version RaduH Linux - Software 3 11-15-2007 12:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration