使用vcpkg编译C++代码,通过libssh库。

huangapple go评论80阅读模式
英文:

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 the 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.
英文:

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 &lt;libssh/libssh.h&gt;
#include &lt;stdlib.h&gt;
 
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&gt;gcc sample.cpp -o sampl
sample.cpp:1:10: fatal error: libssh/libssh.h: No such file or directory
    1 | #include &lt;libssh/libssh.h&gt;
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.

答案1

得分: 1

首先,您应确保使用与您的编译器和架构匹配的正确“三元组”来安装库。
我不知道您的gcc是MingW还是Cygwin。
请参阅此处的说明

其次,您可以按照此处描述的方法使用CMake,或者手动使用-I-L命令行标志指定编译器在哪里查找库头文件和静态库。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月2日 14:21:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定