user-0 提问: 关于调用 libssh2.a

回复:
user: user-1
content: 加QQ1009540871请教，辛苦 辛苦

user: user-1
content: 楼主在没，有问题请教 急急急，，

user: user-0
content: 问题已解决。分享下！！！ 头文件再加个  #include <zlib.h> 编译的时候   [root@gnos-x64-dev ssh2]# gcc -o sftpdir sftpdir.c   libssh2.a    -lcrypto    -lz

user: user-0
content: 这几个头文件是没问题的。。。 [root@gnos-x64-dev include]# pwd  /usr/include [root@gnos-x64-dev include]# find ./ -name "libssh2*" ./libssh2.h ./libssh2_publickey.h ./libssh2_sftp.h

user: user-0
content: #include <libssh2.h> #include <libssh2_sftp.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <errno.h> #include <fcntl.h>  int main(int argc, char **argv) {     unsigned long hostaddr;     int sock, i, auth_pw = 1;     struct sockaddr_in sin;     const char * fingerprint;     LIBSSH2_SESSION *session;     const char *username = "liu";     const char *password = "p3.1415926";     const char *sftppath = "/home/ssh2";     int rc;     LIBSSH2_SFTP *sftp_session;     LIBSSH2_SFTP_HANDLE *sftp_handle;      if(argc > 1)     {         hostaddr = inet_addr(argv[1]);     }     else     {         hostaddr = htonl(0x7F000001); // 127.0.0.1     }          if(argc > 2)     {         username = argv[2];     }      if(argc > 3)     {         password = argv[3];     }      if(argc> 4)     {         sftppath = argv[4];     }      rc = libssh2_init(0);     if(rc != 0)     {         fprintf(stderr, "linssh2 initialization failed (%d)\n", rc);         return 1;     }      sock = socket(AF_INET, SOCK_STREAM, 0);      sin.sin_family = AF_INET;     sin.sin_port = htons(6802);     sin.sin_addr.s_addr = hostaddr;     if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0)     {         fprintf(stderr, "failed to connect!\n");         return -1;     }      session = libssh2_session_init();     if(!session)     {         return -1;     }      rc = libssh2_session_startup(session, sock);     if(rc)     {         fprintf(stderr, "Failure establishing SSH session: %d\n");         return -1;     }      fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);     printf("Fingerprint: ");     for(i = 0; i < 20; i++)     {         printf("%02x ", (unsigned char)fingerprint[i]);     }     printf("\n");      if(auth_pw)     {         if(libssh2_userauth_password(session, username, password))         {             printf("Authentication by password failed!\n");             goto shutdown;         }     }      fprintf(stderr, "libssh2_sftp_init()!\n");     sftp_session = libssh2_sftp_init(session);      if(!sftp_session)     {         fprintf(stderr, "Unable to init SFTP session\n");         goto shutdown;     }      libssh2_session_set_blocking(session, 1);     fprintf(stderr, "libssh2_sftp_opendir()!\n");      //通过SFTP请求目录清单     sftp_handle = libssh2_sftp_opendir(sftp_session, sftppath);     if(!sftp_handle)     {         fprintf(stderr, "Unable to open dir with SFTP\n");         goto shutdown;     }     fprintf(stderr, "libssh2_sftp_opendir() is done, now receive listing!\n");      do{         char mem[512];         char longentry[512];         LIBSSH2_SFTP_ATTRIBUTES attrs;         rc = libssh2_sftp_readdir_ex(sftp_handle, mem, sizeof(mem),                                      longentry, sizeof(longentry), &attrs);          if(rc > 0)           {             if(longentry[0] != '\0')             {                 printf("%s\n", longentry);             }                 else             {                 if(attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS)                 {                     printf("---fix---");                 }                 else                 {                     printf("------");                 }                  if(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID)                 {                     printf("%4ld %4ld ", attrs.uid, attrs.gid);                 }                 else                 {                     printf(" -   -  ");                 }                  if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE)                 {                     printf("%8lld ", attrs.filesize);                 }                  printf("%s\n", mem);             }              }         else             break;     }while(1);      libssh2_sftp_closedir(sftp_handle);     libssh2_sftp_shutdown(sftp_session);  shutdown:     libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing");     libssh2_session_free(session);       close(sock);     printf("all done\n");      libssh2_exit();          return 0; } 这基本是libssh2库的源码，编译 gcc -o ssh sftpdir.c libssh2.a  会弹出很多错误 : 例如 :libssh2.a(crypt.o): In function `crypt_dtor': /home/wang/libssh2-1.2.9/src/crypt.c:111: undefined reference to `EVP_CIPHER_CTX_cleanup' libssh2.a(crypt.o):(.rodata+0xf8): undefined reference to `EVP_aes_256_cbc' libssh2.a(crypt.o):(.rodata+0x138): undefined reference to `EVP_aes_256_cbc' libssh2.a(crypt.o):(.rodata+0x178): undefined reference to `EVP_aes_192_cbc' libssh2.a(crypt.o):(.rodata+0x1b8): undefined reference to `EVP_aes_128_cbc' libssh2.a(crypt.o):(.rodata+0x1f8): undefined reference to `EVP_bf_cbc' libssh2.a(crypt.o):(.rodata+0x238): undefined reference to `EVP_rc4' libssh2.a(crypt.o):(.rodata+0x278): undefined reference to `EVP_rc4' libssh2.a(crypt.o):(.rodata+0x2b8): undefined reference to `EVP_cast5_cbc' libssh2.a(crypt.o):(.rodata+0x2f8): undefined reference to `EVP_des_ede3_cbc'   难道是这个库的问题吗？ 求指导！！！！

user: user-2
content: 第一，我没写过。 第二，这种库的使用应该有例子吧？如果有的话先看看例子，琢磨一下。 第三，看源码是很好的学习过程，有些人想学还看不到源码。

user: user-0
content: 好像在libssh.h里是没有这个结构体。你们有写过sftp的c实现吗？用没有这个结构体。 看源代码看的很是懵啊。

user: user-3
content: LIBSSH2_SFTP show一下定义声明在哪

user: user-2
content: 结构体类型没找到，你少包含了头文件

user: user-0
content: 没人会吗？？？？？？？？？

user: user-0
content: 星期一了，快来顶啊！！！

user: user-0
content: ----上面打错了---- 如果我不使用静态库，(------在linux下解压后libssh2-1.2.9中的例子都可以运行-------------) 我应该怎么利用它的环境。  来人帮忙解答呗！！！！！！！！！ 顶！！！！！！！！！