免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5780 | 回复: 2
打印 上一主题 下一主题

简单的libssh2应用编译不过,请帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-24 09:54 |只看该作者 |倒序浏览
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <libssh2.h>

int connect_to_host(const char *host, char* port) {
        /* 省略建立socket和tcp连接的代码 */
    return sockfd;
}

int main(int argc, char *argv) {
    int sshfd;
    LIBSSH2_SESSION *session;
    LIBSSH2_CHANNEL *channel;
    /* 本地开了SSHD服务 */
    sshfd = connect_to_host("127.0.0.1", "22");
   
    session = libssh2_session_init();
    if (libssh2_session_startup(session, sshfd)) {
        printf("ssh connect error!\n");
        close(sshfd);
        exit(EXIT_FAILURE);
    }
   
    return EXIT_SUCCESS;
}


libssh2: www.libssh2.org

无论是自己编译源代码或apt-get安装libssh2-0-dev包都不行

上面代码的文件名为ssh.c
编译命令:gcc ssh.c
错误信息:

  1. /tmp/cckvJklm.o: In function `main':
  2. ssh.c:(.text+0x197): undefined reference to `libssh2_session_init_ex'
  3. ssh.c:(.text+0x1ac): undefined reference to `libssh2_session_startup'
  4. collect2: ld returned 1 exit status
复制代码


已经确认/usr/include下有libssh2.h, /usr/lib/下有libssh2.so

[ 本帖最后由 Sam1860 于 2007-11-24 10:18 编辑 ]

求职 : 数据库管理员
论坛徽章:
0
2 [报告]
发表于 2007-11-24 10:46 |只看该作者
gcc -o  ssh  ssh.c -lssh2

论坛徽章:
0
3 [报告]
发表于 2007-11-24 11:05 |只看该作者
谢谢你了
对linux应用开发不熟悉,还以为安装在标准目录下的库是不用指定的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP