VC++快捷使用安装libcurl
安装vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
安装libcurl
这里同时带上了 ssl 特性,会自动拉下 OpenSSL 和 zlib。
.\vcpkg install curl[ssl]:x64-windows
工程引用
// 引用头
#include <curl/curl.h>
// 调用内容
void CTestVCPkgDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CURL* curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
AfxMessageBox(CString(curl_easy_strerror(res)));
}
curl_easy_cleanup(curl);
}
CDialogEx::OnOK();
}
检查依赖
使用时需要检查对应生成exe二进制文件的目录检查libcurl,zlib与其他依赖库的dll
比如我使用的时候,对应自动检出了libcurl-d.dll和zlibd1.dll这两个在发布和运行时也需要与程序一起打包。