1

I installed libssh through vcpkg on my Windows 8.1 machine.

vcpkg install libssh

Now I am trying to compile my c++ code making use of libssh.

#include <libssh/libssh.h>
#include <stdlib.h>
 
int main()
{
  ssh_session my_ssh_session = ssh_new();
  if (my_ssh_session == NULL)
    exit(-1);
  ...
  ssh_free(my_ssh_session);
}

But I am receiving following error.

D:\remoteDesktopTimeZone>gcc sample.cpp -o sampl
sample.cpp:1:10: fatal error: libssh/libssh.h: No such file or directory
    1 | #include <libssh/libssh.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
vvv444
  • 2,764
  • 1
  • 14
  • 25
  • 1
    There are two things you need to do. First you need to add a `-I something` option to your command line. This tells the compiler where to find the SSH header file, just replace 'something' with the correct location (whatever that is in your case). Then you need to add `-lssh` to your command line, this tells the compiler to link with the SSH library. It seems to be a common misunderstanding of third party libraries that all you need to do is install something and everything will work automatically. Building C or C++ programs is not that simple. – john Jun 02 '23 at 06:25
  • On a side note, your program and your compiler are for the C language. This is not the same language as C++. – john Jun 02 '23 at 06:28
  • Thanks john. Your inputs also helped. – Madhusudhana Jun 02 '23 at 09:33

1 Answers1

1

First, you should ensure that you are installing libraries with correct "triplet" matching your compiler and architecture. I don't know if your gcc is MingW or Cygwin. See instructions here.

Second, you should either use CMake as described here, or manually point the compiler where to find the library headers and static libraries using the -I and -L command line flags.

vvv444
  • 2,764
  • 1
  • 14
  • 25