libssh2 和 C++
当我尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将调用更改为 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.
如果 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 useextern "C" {}
itself.)