配置背景
在项目中用到QNetworkAccessManager
实现POST请求,但是一直报错UnknownNetworkError
。
在客户那边有十台左右PC,只有一台PC上的客户端软件报错。这台机器也能访问到目标地址,于是想着用其他库去完成POST请求,测试是否是QT库的问题。
使用vcpkg安装libcurl
如果没有将vcpkg.exe所在目录配置到环境变量中,需要cd到所在目录,通过powershell或者cmd运行以下指令
.\vcpkg.exe install curl:x64-windows
引用库
在引用库的时候,我按照教程在CMakeLists.txt中添加了以下片段
set(CMAKE_TOOLCHAIN_FILE "C:\\src\\vcpkg\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" )
find_package(CURL CONFIG REQUIRED)
target_link_libraries(testcurl PRIVATE CURL::libcurl)
结果报错:
error: Could not find a package configuration file provided by "CURL" with any of the following names: CURLConfig.cmake curl-config.cmake Add the installation prefix of "CURL" to CMAKE_PREFIX_PATH or set "CURL_DIR" to a directory containing one of the above files. If "CURL" provides a separate development package or SDK, be sure it has been installed.
解决方案:
再添加两句
set(CURL_DIR "C:\\src\\vcpkg\\vcpkg\\installed\\x64-windows\\share\\curl")
set(ZLIB_ROOT "C:\\src\\vcpkg\\vcpkg\\installed\\x64-windows")