当前位置:网站首页>Win10 compiles curl library source code with cmake3.22 and vs2019 and calls
Win10 compiles curl library source code with cmake3.22 and vs2019 and calls
2022-06-28 17:18:00 【Ten thousand miles' journey to】
curl Is a use of URL Syntax file transfer tool that works on the command line , Support many kinds of http Request operation , For details, please refer to Linux curl The most complete and detailed explanation of the command _Angel_CG The blog of -CSDN Blog _curl command .curl Now in linux And win10 Built in , You can use... Directly from the command line curl Instructions . Bloggers have been looking for it for a long time , None of them are applicable to vs Of curl win10 library , So I found curl The source code of the library has been compiled , And through the command line call and c++ call .
curl Download the source code of the library :https://github.com/curl/curl
Blogger compilation environment :vs2019,cmake3.22 ( There are no special settings during compilation , So the blogger decided to do something else vs、cnake The version should also be completely OK )
1、 Download and extract the source code
stay github After downloading zip After unpacking the package, you will get the following directory structure , And create... In the following directory build Catalog ( For subsequent cmake).

2、cmake Generate vs project
open cmake, Match the source code path to build Fill in the path to the corresponding position in the following figure . Then click Configure( The process will pop up vs Options , Select the default value )、Generate、Open Project. Click on Open Project Will be in vs Open project in .

3、vs Generate library files
here VS The interface is shown in the following figure , First install your own requirements Release/Debug ,x64/32 Equal Edition . then , Click Select ALL_BUILD project , Right click and click generate in the pop-up interface . Last , Project generation succeeded . The output results can be seen in the red box at the bottom of the figure below .

Get into build Catalog , The generated file directory is as follows .
Generated lib And dll As shown in the figure below

Generated curl.exe As shown in the figure below , The red box shows the bloggers' followers lib/Release Copy it . Because execution curl.exe Need to call libcurl.dll.

4、curl.exe test
With the system's own curl comparison , Compiled by bloggers curl.exe Obviously not https,ftps And so on , In contrast, bloggers do not configure at compile time openssl Caused by .

5、libcurl test
First step newly build vs c++ Empty item
The second step To configure vs project
Configure... In the appropriate location include、lib The path of . And in the linker -》 Input -》 Configure... In additional dependencies libcurl_imp.lib;

The third step To write C++ Test code
The test code is as follows
#include <iostream>
#include <string>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <curl/curl.h>
using namespace std;
bool read_file(const char* path, const char* local_file)
{
cout << "download " << path << " to local: " << local_file << endl;
string url = path;
CURL* conn = curl_easy_init();
if (conn == NULL) {
fprintf(stderr, "Failed to create CURL connection\n");
return false;
}
std::cout << "down file from:" << url << std::endl;
curl_easy_setopt(conn, CURLOPT_URL, url.c_str());
// Set no authentication https Of ssl certificate
curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0)
;
curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_GSSNEGOTIATE);
curl_easy_setopt(conn, CURLOPT_USERNAME, "");
curl_easy_setopt(conn, CURLOPT_PASSWORD, "");
curl_easy_setopt(conn, CURLOPT_COOKIE, "cookiejar.txt");// Set up cookie 【 Occurs on the server 】
curl_easy_setopt(conn, CURLOPT_COOKIEFILE, "cookiejar.txt");// Set up cookie 【 Server operations cookie After saving 】
//curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);
//curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, write_data);
FILE* target = fopen(local_file, "wb");
if (target == NULL) {
fprintf(stderr, "Failed to open [%s], errno: %d\n", local_file, errno);
return false;
}
curl_easy_setopt(conn, CURLOPT_WRITEDATA, target);
CURLcode code = curl_easy_perform(conn);
if (code != CURLE_OK) {
fprintf(stderr, "Failed to get file [%s]\n", curl_easy_strerror(code));
return false;
}
fclose(target);
curl_easy_cleanup(conn);
return true;
}
int main() {
read_file("https://codeload.github.com/curl/curl/zip/refs/heads/master","curl.zip");
return 0;
}
The code execution result is shown in the figure below , It should be noted that dll The file should be consistent with exe In the same path , Or will dll Add the path of the file to the system environment variable path in .

边栏推荐
- MySQL高可用之MHA(一不小心和我的青春擦肩而過)
- VirtualBox中克隆了一个虚拟系统出现IP问题
- 【TcaplusDB知识库】查看tcapdir目录服务器
- RHEL6.4中使用Cacti+Spine监控远程主机
- Problems encountered in local deployment conflict: MySQL database code, isolation level and verification code are not displayed
- 【TcaplusDB知识库】查看业务密码
- This simple little function saves 213 hours for our production research team in half a year
- logback 日志输出格式
- Introduction to LTSpice circuit simulation
- This simple little function saves 213 hours for our production research team in half a year
猜你喜欢

解决sqoop出现 ERROR manager.SqlManager: Generic SqlManager.listDatabases() not implemented

NoSQL redis configuration and optimization (I blew the night breeze of Qinhuai River for you when you were not in Nanjing)

Redis主从复制、哨兵、cluster集群原理+实验(好好等,会晚些,但会更好)

AUTOSAR software development training

「杰伦熊」暴跌96.6% 明星带货NFT为何遇冷?

关于接口测试自动化的总结与思考

Tianyi cloud web application firewall (edge cloud version) passed the first batch of trusted authentication

CSDN博客专家

Practice of curve replacing CEPH in Netease cloud music

NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
随机推荐
关于接口测试自动化的总结与思考
[tcapulusdb] I wish you all a healthy Dragon Boat Festival!
Cross cluster deployment of helm applications using karmada
Panorama of enterprise power in China SSD industry
[tcapulusdb knowledge base] view the business password
MetaQ安装部署文档
「杰伦熊」暴跌96.6% 明星带货NFT为何遇冷?
IDC:阿里云获2021中国数据治理平台市场份额第一
【离散数学】单射、满射与双射
如何将你的 WordPress 网站置于维护模式
Differences between shared hosts and WordPress hosts
MySQL中的日志管理 日志备份与恢复
MySQL高可用之MHA(一不小心和我的青春擦肩而过)
天翼云Web应用防火墙(边缘云版)通过首批可信认证
Rsync remote synchronization (sunset is especially gentle, and the world is romantic)
ICML 2022 | transferable imitation learning method based on decoupling gradient optimization
The intelligent transformation is accelerated, and enterprises need a new toolbox
Krack based network attack "suggestions collection"
What is the reason why easycvr can't watch the device video when it is connected to the home protocol?
opencv 读取图片详解