使用libssh的链接期间未定义符号 [英] Undefined symbol during link using libssh

查看:115
本文介绍了使用libssh的链接期间未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用libssh来完成两个系统之间的连接,ssh服务器是redhat,客户端是CentOS.

I am using libssh to accomplish connectivity between two systems, the ssh server is redhat, and the client is CentOS.

我的代码可以很好地进行编译和链接,除了在运行时,我一直看到这一点,

My code compiles and links just fine, except, at runtime I keep seeing this,

[1] libssh 0.5.5 (c) 2003-2010 Aris Adamantiadis (aris@0xbadc0de.be) Distributed under the LGPL, please refer to COPYING file for information about your rights, using threading threads_noop
[2] Nonblocking connection socket: 4
[2] Socket connecting, now waiting for the callbacks to work
[1] Socket connection callback: 1 (0)
[1] SSH server banner: SSH-2.0-OpenSSH_5.3
[1] Analyzing banner: SSH-2.0-OpenSSH_5.3
[1] We are talking to an OpenSSH client version: 5.3 (50300)
[2] Received SSH_KEXDH_REPLY
[2] SSH_MSG_NEWKEYS sent
[2] Received SSH_MSG_NEWKEYS
./sshclient: symbol lookup error: ./sshclient: undefined symbol: ssh_pki_import_privkey_file

代码如下:

int main()
{
    ssh_session my_ssh_session;
    ssh_key *pubkey,*privkey;
    int verbosity = SSH_LOG_PROTOCOL;
    int port = 5022,rc;
    char username[20];

    strcpy(username,"yoda"); //assigned a user name
    my_ssh_session = ssh_new();
    if (my_ssh_session == NULL)
            exit(-1);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "XX.XX.XX.XX");
    ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
    ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, username);

    rc = ssh_connect(my_ssh_session);
    if(rc != SSH_OK){
            fprintf(stderr, "Error connecting to host: %s\n",ssh_get_error(my_ssh_session));
            exit(-1);
    }
    rc = ssh_pki_import_privkey_file("/home/yoda/keys/id_rsa",NULL,NULL,NULL,privkey);
    if(rc != SSH_OK){
            fprintf(stderr, "Custom Message: Private Key unacceptable.\n");
            exit(-1);
    }
    fprintf(stdout, "Custom Message: Here now.\n");
    rc = ssh_userauth_publickey(my_ssh_session, NULL, *privkey);
    if(rc == SSH_AUTH_ERROR){
            fprintf(stderr, "Custom Message: A serious error has occured during authentication.\n");
            exit(-1);
    }
    if(rc == SSH_AUTH_DENIED){
            fprintf(stderr, "Custom Message: Unacceptable key or method.\n");
            exit(-1);
    }
    if(rc == SSH_AUTH_PARTIAL){
            fprintf(stderr, "Custom Message: Partially authenticated user.\n");
            exit(-1);
    }
    ssh_key_free(*pubkey);
    ssh_key_free(*privkey);
    ssh_disconnect(my_ssh_session);
    ssh_free(my_ssh_session);
    return(0);
}

我知道这段代码有很多问题,但是在这一点上,我是第一次尝试使用该库,并且更加关注使其能够正常工作.任何对正在发生的事情的见识,将不胜感激.

I know there are a bunch of problems with this code but at this point, I am experimenting with this library for the first time and more concerned with getting it to work. Any insight into whats going on would be appreciated.

推荐答案

libssh 0.5不再维护.您应该使用libssh 0.6.如果我没记错的话,ssh_pki_import_privkey_file()仅适用于libssh 0.6 ...

libssh 0.5 is out of maintenance. You should use libssh 0.6. If I remember correctly ssh_pki_import_privkey_file() is only available with libssh 0.6 ...

这篇关于使用libssh的链接期间未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆