当前位置:网站首页>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 .

边栏推荐
- 本地部署Confluence遇到的问题:MySQL数据库编码、隔离级别、验证码不显示
- EasyCVR播放视频出现卡顿花屏时如何解决?
- 听说转行软件测试只能自学,培训机构是个坑?
- Js中的Bom
- [World Ocean Day] tcapulusdb calls on you to protect marine biodiversity together
- offsetwidth\clientwidth\scrollwidth
- 居家高效远程办公 | 社区征文
- Inspur network wins step by step
- Squid代理服务器应用(我从远方赶来,赴你一面之约)
- R programming language - Introduction
猜你喜欢

Log management in MySQL log backup and recovery

Lucky draw animation - Carp jumps over the dragon's gate

PotPlayer播放百度雲盤視頻

Redis持久化(少年一貫快馬揚帆,道阻且長不轉彎)

Redis persistence (young people always set sail with a fast horse, with obstacles and long turns)

本地部署Confluence遇到的问题:MySQL数据库编码、隔离级别、验证码不显示

Batch modify specified character file name bat script

ZABBIX monitoring of traditional operation and maintenance (you get up early, I get up early, and we will get together sooner or later)

Squid代理服务器应用(我从远方赶来,赴你一面之约)

Summary and Thinking on interface test automation
随机推荐
NoSQL redis configuration and optimization (I blew the night breeze of Qinhuai River for you when you were not in Nanjing)
How to back up a WordPress database
55. maximum sum of continuous subarrays
Metaq installation deployment document
[daily 3 questions (2)] maximum ascending subarray sum
"Popular science leaders say" intelligent bionic robot fish
编写自己的 WordPress 模板
Monitoring remote host with cacti+spine in rhel6.4
居家高效远程办公 | 社区征文
Which securities company is better and safer to choose for opening an exchange fund account by mobile phone
IDC:阿里云获2021中国数据治理平台市场份额第一
Flex layout
几行代码就能实现复杂的 Excel 导入导出,这个工具类真心强大!
Apache setting timeout parameter
MySQL中的日志管理 日志备份与恢复
Batch modify specified character file name bat script
[tcapulusdb knowledge base] batch copy the game area
Visubit "ai+3d vision" product series | loading assembly workstation
Redis persistence (young people always set sail with a fast horse, with obstacles and long turns)
Differences between shared hosts and WordPress hosts