当我尝试在我的C++类中使用libssh2时,始终出现以下错误:

undefined reference to `libssh2_session_init_ex'
undefined reference to `libssh2_session_startup'

If I do the same thing using C, everything works fine.

Any help?

Following is the build command

g++ -Wall -g -I/libssh2-1.2.4/src -I/libssh2-1.2.4/include -L/libssh2-1.2.4/src/obj -L/openssl-0.9.8k/ -L/SecuritySDK/3.0.13/RC/LATEST/security/lib  -lssh2 -ldl -lnsl -lresolv -lhash -lhandlers -lcrypto -lssl -lz -lbpwp3   rhost.o rpipe.o rutils.o -o rpipe

以下是类成员函数
void rhost::InitSession()
{
    m_session = libssh2_session_init();
    if ( libssh2_session_startup(m_session, m_sock) )
    {
        fprintf (stderr, "Failure establishing SSH session\n");
        exit(-1);
    }
    return;
}

是的,平台是Linux

最佳答案

将您的 call 更改为g++ -Wall -g -I/libssh2-1.2.4/src -I/libssh2-1.2.4/include -L/libssh2-1.2.4/src/obj -L/openssl-0.9.8k/ -L/SecuritySDK/3.0.13/RC/LATEST/security/lib rhost.o rpipe.o rutils.o -o rpip -lssh2 -ldl -lnsl -lresolv -lhash -lhandlers -lcrypto -lssl -lz -lbpwp3

参数列表中库和目标文件的顺序很重要。了解有关here的信息。

关于c++ - libssh2和C++,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4615563/

10-15 01:35