我正在尝试将 libssh 与 C++ 包装器 libsshpp.hpp 一起使用(它是从 libssh.h 中包装的,它是用 C 编写的 libssh 库)。起初我尝试在示例目录中从 libsshpp.cpp 构建代码g++ -o sshpp libsshpp.cpp -lssh
#include <iostream>
#include <string>
#include <libssh/libsshpp.hpp>
int main(int argc, const char **argv){
ssh::Session session;
try {
if(argc>1)
session.setOption(SSH_OPTIONS_HOST,argv[1]);
else
session.setOption(SSH_OPTIONS_HOST,"localhost");
session.connect();
session.userauthPublickeyAuto();
session.disconnect();
} catch (ssh::SshException e){
std::cout << "Error during connection : ";
std::cout << e.getError() << std::endl;
}
return 0;
}
构建成功,但是当执行 sshpp 时,它显示错误:./sshpp: symbol lookup error: ./sshpp: undefined symbol: ssh_userauth_publickey_auto
。
我在 libsshpp.cpp 中查找:
int userauthPublickeyAuto(void){
int ret=ssh_userauth_publickey_auto(c_session, NULL, NULL);
ssh_throw(ret);
return ret;
}
在 libssh.h 中:
LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session,
const char *username,
const char *passphrase);
希望任何有 libssh 经验的人都可以提供帮助