在 Visual Studio 2019 中使用 libcurl 时生成错误

问题描述 投票:0回答:2

我正在尝试让 libcurl 工作。我是第一次使用 libcurl。我使用 vcpkg 安装了 libcurl。

C:\Users\infib\vcpkg>vcpkg install curl
The following packages are already installed:
curl[core,ssl,tool,winssl]:x86-windows 
Starting package 1/1: curl:x86-windows
Package curl:x86-windows is already installed
Elapsed time for package curl:x86-windows: 4.298 ms

Total elapsed time: 4.956 ms

The package curl:x86-windows provides CMake targets:

find_package(CURL CONFIG REQUIRED)
target_link_libraries(main PRIVATE CURL::libcurl)

我安装了 opencv64 位,并且尝试使用 libcurl,但出现了很多错误。

error LNK2019: unresolved external symbol __imp_curl_easy_init
error LNK2019: unresolved external symbol __imp_curl_easy_setopt 
error LNK2019: unresolved external symbol __imp_curl_easy_perform 
error LNK2019: unresolved external symbol __imp_curl_easy_cleanup 
error LNK2019: unresolved external symbol __imp_curl_easy_getinfo

1>libcurl_a.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type    'x64'
1>libcurl-d.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>libcurl.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>WINMM.LIB : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>wldap32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>ws2_32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'

有人可以告诉我如何克服这个错误吗?我包含了在 vcpkg 包文件夹中找到的 libcurl.lib,但仍然收到此错误。我尝试了stackover flow libcurl thread中提到的所有方法,但仍然收到错误。

请让我知道如何解决这个问题。

visual-studio libcurl
2个回答
0
投票

看来您问题的核心是 x64 与 x86。 vcpkg 可能正在引入 x86 版本。老实说,我使用的解决方案是直接拉取curl的源代码并使用cmake。获得源代码后,您需要运行这样的脚本(在curl目录中):

mkdir build32 推送构建32 cmake -G“Visual Studio 16 2019”-A Win32 .. 波普德 cmake --build build32 // 这将为您编译它

mkdir build64 推构建64 cmake -G“Visual Studio 16 2019”-A x64 .. 波普德 cmake --build build64 // 与上面相同

这将创建一个共享库。如果您想要一个静态库,您将需要进入 CMakeLists.txt 文件并更新

选项(BUILD_SHARED_LIBS“构建共享库”ON)

选项(BUILD_SHARED_LIBS“构建共享库”关闭)

这将启用静态构建。

您将在各自的构建下找到必要的.lib和.dll文件 lib 和类型文件夹,例如debug 64 将是 build64\lib\Debug

希望这有帮助。


0
投票

vcpkg 默认安装 x86 库。 当你的项目架构是x64时,你必须通过指定三元组来安装x64的curl库,如下所示。 (来自 https://github.com/microsoft/vcpkg#quick-start-windows

> ./vcpkg install curl:x64-windows

> ./vcpkg install curl --triplet=x64-windows

您还可以安装多个架构库

> ./vcpkg install curl:x86-windows curl:x64-windows
© www.soinside.com 2019 - 2024. All rights reserved.