Search code examples
c++vcpkglibssh

Compiling C++ code using libssh library through vcpkg


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.

Solution

  • 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.