VS2019 + libcurl5.7.0 + openssl编译配置
1、用途
工作用到C++对求高德地图发送https请求,进行逆地址分析。
2、文件包下载
2.1 window的openssl3.0.5EXE安装包
链接:exe安装包
2.2 下载libcurl5.7.0版本
链接:libcurl5.7.0
3、编译
3.1 openssl3.0.5exe编译。
选择同意协议,请勾选:The OpenSSL binaries(/bin) directory,默认安装。
安装完毕,打开OpenSSL-Win64文件夹:libcrypto-3-x64.dll和libssl-3-x64.dll可放在后面测试文档exe中。
文件夹include、lib为libcurl指定编译文件夹,目的是编译libcurl的openssl库。
3.2 编译libcurl5.7.0
3.2.1 打开curl-all.sln文件。
打开xx\curl-7.80.0\projects\Windows\VC15\curl-all.sln工程 文件,选择DLL Release-DLL OpenSSL和DLL Debug-DLL OpenSSL进行编译。
3.2.2 设置编译工程文件。
curl-all.sln文件有curl和libcurl工程文件,对工程文件进行debug和release版本分别设置.。
头文件为步骤3.1中openssl的include文件夹:C:\Program Files\OpenSSL-Win64\include;
库文件为步骤3.1中openssl的lib文件,库文件不需要输入直接进行配置,源码已经已经把相关文件信息写入。
编译完成后,会在源码文件夹的curl-7.8.0/build/Win64/VC15下生成两个文件夹DLL Debug - DLL OpenSSL和DLL Release - DLL OpenSSL。
4、测试
由于工程涉及到高德地图API的key,不便公开,故采用参考文章2的测试代码。
#include <iostream>
#include"curl/curl.h"
void testssh()
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, true);
curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
}
int main()
{
testssh();
std::cout << "Hello World!\n";
}
5、参考文章
参考文章1:windows 下编译libcurl + openssl
参考文章2:libcurl带openssl文件的编译
6、测试文件下载
libcurl5.7+openssl3.0.5库链接