libssh2 和 C++

发布于 2024-10-10 19:42:47 字数 790 浏览 0 评论 0原文

当我尝试在 C++ 类中使用 libssh2 时,我不断收到以下错误:

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

如果我使用 C 做同样的事情,则一切正常。

有什么帮助吗?

以下是构建命令

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

When I try to use libssh2 in my C++ class, I keep getting the following errors:

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

following is the class member function

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;
}

Yes platform is linux

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-10-17 19:42:47

将调用更改为 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。

参数列表中库和目标文件的顺序很重要。 此处了解相关内容。

Change your call to 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.

The order of libraries and object files in the parameter list matters. Read about it here.

纵情客 2024-10-17 19:42:47

如果 C 有效而 C++ 无效,那么听起来您未能将 libssh2 函数原型包含在 extern "C" {} 块中,如 此处。 (您应该仔细检查头文件;令我有点惊讶的是它本身没有使用 extern "C" {} 。)

If C works and C++ doesn't, then it sounds like you're failing to include the libssh2 function prototypes in an extern "C" {} block, as described here. (You should double-check the header file; I'm a bit surprised that it doesn't use extern "C" {} itself.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文