编译不带openssl的版本的libcurl
我的编译环境
vs 2019
libcurl 7.75
1.下载库文件
git clone https://github.com/curl/curl.git
2. 生成工程文件
3. 打开工程文件
4. 修改工程配置编译即可。
5. 编译成功。
二、编译带有openssl的libcurl
下载编译需要的库
git clone https://github.com/openssl/openssl.git
git clone https://github.com/libssh2/libssh2.git
下载后,目录排列如下,三个库都在同级目录
进入vc的开发cmd命令下:
运行下面命令 vc2019 命令是14.2 ,如果用其他vc版本,类推
build-openssl vc14.2 x64 release ../../openssl
这一步耗费时间非常长
工程选择,编译
include C:\Users\alantop\Desktop\openssl\build\Win64\VC14.20\LIB Release\include
使用库
\#include <curl/curl.h>
? \#pragma comment(lib, "libcurl.lib")
BUILD_LIBCURL
CURL_STATICLIB
三 8.1版本的不需要再编译
1. 官网下载 8.1.2
https://curl.se/download.html
2. 环境变量的设置
3.软件工程设置
libbrotlicommon.a
libbrotlidec.a
libcrypto.a
libcurl.a
libcurl.dll.a
libgsasl.a
libnghttp2.a
libnghttp3.a
libngtcp2.a
libngtcp2_crypto_openssl.a
libssh2.a
libssl.a
libz.a
libzstd.a
4.测试代码
#include <curl/curl.h>
int main(int argc, char* argv[]) {
CURL* curl = nullptr;
CURLcode res;
curl = curl_easy_init();
if (curl != nullptr) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}