0

I am trying to build a simple SSH client from Wil Allsopp's pen testing book. Working on Mac OS High Sierra with gcc-4.2 with libssh installed using Homebrew. The simplest version of the code is:

#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{    
    ssh_session my_ssh_session;
    my_ssh_session = ssh_new();
    ssh_free(my_ssh_session);
    return 0;
}

However a simple gcc build (gcc -Wall ssh_client.c) produces the following error:

Undefined symbols for architecture x86_64:

"_ssh_free", referenced from: _main in ssh_client-aa8f09.o

"_ssh_new", referenced from: _main in ssh_client-aa8f09.o

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1

Can anyone explain these errors and how I can fix them?

valiano
  • 16,433
  • 7
  • 64
  • 79

1 Answers1

0

Your build line doesn't appear to contain any include and linker flags. I imagine it is picking up the headers but not the library for ssh to link against. Have a look into pkgconfig for an easy way to maintain this.

Paul Childs
  • 229
  • 2
  • 9
  • Yes, you are probably right. I have been away from c programming and gcc for a very long time. I will look into the documentation for pkgconfig. Thank you. – user2759923 Apr 25 '18 at 00:02
  • take a look on this post https://stackoverflow.com/questions/51074521/link-libssh-with-static-library-libssh-a it helped me to build executable, but still need some time to understand how linking works – Ihor Bats Jan 01 '19 at 21:52