libssh问题编译问题未定义错误

时间:2018-09-22 05:50:10

标签: c++

您好,我是c ++的新手,我正尝试通过ssh连接在这里工作 它向我指出,我需要链接库...这是怎么做的?

#include <libssh/libssh.h>
#include <stdlib.h>

int main()
{
  ssh_session my_ssh_session;
  my_ssh_session = ssh_new(); 
  int verbosity = SSH_LOG_PROTOCOL;
  int port = 22;
  ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
  ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
  ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
  ssh_free(my_ssh_session);
}

我不断收到此错误

[brett@badbox sshcpp1]$ make
g++ -Wl,-O1 -Wl,-z,relro -o sshcpp1 main.o   -lQt5Core -lpthread 
main.o: In function `main':
/home/brett/sshcpp1/main.cpp:7: undefined reference to `ssh_new'
/home/brett/sshcpp1/main.cpp:10: undefined reference to `ssh_options_set'
/home/brett/sshcpp1/main.cpp:11: undefined reference to `ssh_options_set'
/home/brett/sshcpp1/main.cpp:12: undefined reference to `ssh_options_set'
/home/brett/sshcpp1/main.cpp:13: undefined reference to `ssh_free'
collect2: error: ld returned 1 exit status
make: *** [sshcpp1] Error 1

Outocomplete似乎正在使用ssh库。

我在做什么错??

1 个答案:

答案 0 :(得分:1)

您需要通过在链接器命令中添加libssh来链接-lssh