curl 为什么我的windows环境不能正确安装外部C++库?

4si2a6ki  于 2023-03-03  发布在  Windows
关注(0)|答案(1)|浏览(159)

描述

大家好,我是C++的新手,在使用外部库时遇到了困难:
我目前运行的是Windows 10,并试图在我的机器上安装一个像libcurl这样的库。我已经使用msys2和vcpkg安装了它。当使用g ++和including curl编译代码时,#include找不到,因为我的编译器找不到链接库。
我也不太确定这个库安装在哪里。

Msys2安装:

**pacman -Sy mingw-w64-x86_64-curl**

 mingw32 is up to date
 mingw64 is up to date
 ucrt64 is up to date
 clang32 is up to date
 clang64 is up to date
 msys is up to date
warning: mingw-w64-x86_64-curl-7.86.0-5 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) mingw-w64-x86_64-curl-7.86.0-5

Total Installed Size:  3.07 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                               [###############################] 100%
(1/1) checking package integrity                             [###############################] 100%
(1/1) loading package files                                  [###############################] 100%
(1/1) checking for file conflicts                            [###############################] 100%
(1/1) checking available disk space                          [###############################] 100%
:: Processing package changes...
(1/1) reinstalling mingw-w64-x86_64-curl                     [###############################] 100%

**pkg-config --cflags libcurl**

Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcurl', required by 'virtual:world', not found

**pkg-config --libs libcurl**

Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcurl', required by 'virtual:world', not found

Vcpkg安装:

**vcpkg install curl:x64-windows**

The following packages are already installed:
    curl[core,non-http,schannel,ssl,sspi]:x64-windows -> 7.84.0#2
curl:x64-windows is already installed
Restored 0 package(s) from C:\Users\Joseph Kan\AppData\Local\vcpkg\archives in 533.8 us. Use --debug to see more details.
Total install time: 1.645 ms
curl provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(CURL CONFIG REQUIRED)
    target_link_libraries(main PRIVATE CURL::libcurl)

G ++编译:

**g++ -o sample sample.cpp sampleInterface.cpp -lcurl**

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lcurl
collect2.exe: error: ld returned 1 exit status
vcirk6k6

vcirk6k61#

答案很简单:
错误的三元组。x64-windows是MSVC三元组。
您可能需要x64-mingw-dynamic
此外:要使pkg-config与vcpkg一起工作,您需要设置PKG_CONFIG_PATH,例如:

<VCPKG_INSTALLED_DIR>/lib/pkgconfig

如果不这样做,vcpkg就不会神奇地添加到pkg-config的搜索路径中......

相关问题