gpt4 book ai didi

c - 如何在 Visual Studio 代码中将 libssh2 包含到 c 项目

转载 作者:行者123 更新时间:2023-11-30 14:34:17 28 4
gpt4 key购买 nike

我正在尝试运行一个使用 libssh2 库的简单 C 程序。对于安装(构建+安装),我使用了 cmake-gui(我使用的是 Windows 10 x64),openSSL 选项处于打开状态,zlib 处于关闭状态。

我正在尝试不同的解决方案来包含具有正确依赖项的库,但每次都会显示不同的错误消息。像:

当我仅包含 ssh2 库路径时 -I "C:\\Program Files (x86)\\libssh2\\include"-L "C:\\Program Files (x86)\\libssh2\\lib"-lssh2

错误信息:

C:\Program Files (x86)\libssh2\lib/libssh2.a(openssl.c.obj):openssl.c:(.text+0x38): undefined reference to 'BN_bn2bin'

C:\Program Files (x86)\libssh2\lib/libssh2.a(openssl.c.obj):openssl.c:(.rdata$.refptr.PEM_read_bio_ECPrivateKey[.refptr.PEM_read_bio_ECPrivateKey]+0x0): undefined reference to 'PEM_read_bio_ECPrivateKey'

C:\Program Files (x86)\libssh2\lib/libssh2.a(pem.c.obj):pem.c:(.text+0x6dd): undefined reference to 'EVP_DigestUpdate'

C:\Program Files (x86)\libssh2\lib/libssh2.a(bcrypt_pbkdf.c.obj):bcrypt_pbkdf.c:(.text+0x3bb): undefined reference to 'EVP_DigestUpdate'

C:\Program Files (x86)\libssh2\lib/libssh2.a(crypt.c.obj):crypt.c:(.text+0x156): undefined reference to 'EVP_CIPHER_CTX_free'

我没有发布所有错误消息,但我注意到“()”中的那些库像 crypt 和 openssl 一样困惑。所以我尝试通过将 openSSL 安装目录的路径添加到编译器参数中来包含它们: -I 'C:\Program Files (x86)\libssh2\include' -I C:\OpenSSL-Win64\include -L 'C:\Program Files (x86)\libssh2\lib' -L C:\OpenSSL-Win64\lib -lssh2 -lws2_32 -lcrypto -lssl但它不起作用,因为他找不到这些库:

cannot find -lcrypto

cannot find -lssl the openSSL installation folder has the include folder with theesheaders files and the lib folder with .lib files (and i'm not sure 100% if the mingw64 can use those extension or it should be .a).

也许这个问题之前被问过,但经过几天的搜索,我找不到适合我的解决方案。对于重复的帖子深表歉意。

这是我的任务文件:

{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-6.2.0-win32-seh-rt_v5-rev1\\mingw64\\bin\\gcc.exe",
"args": [
"-Wall",
"-Wextra",
"-g",
"${file}",
"-I",
"C:\\Program Files (x86)\\libssh2\\include",
"-I",
"C:\\OpenSSL-Win64\\include",
"-L",
"C:\\Program Files (x86)\\libssh2\\lib",
"-L",
"C:\\OpenSSL-Win64\\lib",
"-lssh2",
"-lws2_32",
"-lcrypto",
"-lssl",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-6.2.0-win32-seh-rt_v5-rev1\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "Run active file",
"command":".\\${fileBasenameNoExtension}.exe"
}
]

}

我不确定您是否需要 c_cpp_properites 文件:

{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.10586.0",
"compilerPath": "\"C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/bin/gcc.exe\"",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4

}

最佳答案

您始终需要链接应用程序或共享库的依赖项(您使用 -lssh2 完成),但如果您正在进行静态构建,则还需要包含以下依赖项依赖关系。

在 Linux 上或在 Windows 上使用 MSYS2 时,您可以使用 pkg-config.exe 获取实际的链接参数,如下所示:

pkg-config.exe --static --libs libssh2

在我的例子中返回:

-LD:/Prog/winlibs64-9.2.0-7.0.0/custombuilt/lib -lssh2 -lws2_32 -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lz

关于c - 如何在 Visual Studio 代码中将 libssh2 包含到 c 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59022518/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com