1

Hi im brand new to c++ im trying to get a ssh connection to work here is my code Its been pointed out to me i need to link the libraries ... how is this done?

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

I keep getting this error

[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 seems to be picking up the ssh library.

What am i doing wrong??

Brett
  • 376
  • 7
  • 24
  • In short: you’re not linking in the ssh library – Sami Kuhmonen Sep 22 '18 at 06:21
  • How do i do that? link the library? – Brett Sep 22 '18 at 06:24
  • @Sami Kuhmonen how do i link my library? – Brett Sep 22 '18 at 06:25
  • Closely related, [How do I properly link libssh?](https://stackoverflow.com/q/37336455/608639), [How to link a simple libssh program](https://stackoverflow.com/q/41763200/608639), and [Undefined symbol during link using libssh](https://stackoverflow.com/q/26655432/608639) – jww Sep 22 '18 at 07:27

1 Answers1

2

You need to link libssh by adding -lssh to your linker command.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436