日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

在windows下,编译可访问https的libcurl静态库过程

發(fā)布時(shí)間:2023/11/30 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在windows下,编译可访问https的libcurl静态库过程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 首先編譯openssl靜態(tài)庫

整個(gè)過程用的是 vs2015命令提示工具

需要安裝perl
下載地址:添加鏈接描述
解壓后, 在 openssl-1.0.2e目錄下創(chuàng)建develop這個(gè)文件夾, cd到 openssl-1.0.2e目錄下,

a.配置編譯文件和模式
執(zhí)行

perl Configure VC-WIN32 no-asm --prefix=E:\curl\openssl-1.0.2e\develop

VC-WIN32標(biāo)識windows 32位操作系統(tǒng),
64位用VC-WIN64A表示, 若要使用debug版本,請使用debug-VC-WIN64A或debug-VC-WIN32
no-asm 表示不用匯編
–prefix=E:\curl\openssl-1.0.2e\develop 是設(shè)置安裝目錄
b.生成編譯配置文件
若為Windows 64位系統(tǒng),執(zhí)行

ms\do_win64a.bat

若為Windows 32位系統(tǒng),執(zhí)行

ms\do_ms.bat

執(zhí)行這一步之后,在ms目錄下會(huì)生成nt.mak和ntdll.mak兩個(gè)編譯配置文件
nt.mak 用于生成靜態(tài)lib庫
ntdll.mak 用于生成動(dòng)態(tài)dll庫
c.編譯
靜態(tài)庫

nmake -f ms\nt.mak

動(dòng)態(tài)庫

nmake -f ms\ntdll.mak

d.測試
測試靜態(tài)庫:

nmake -f ms\nt.mak test

測試動(dòng)態(tài)庫:

nmake -f ms\ntdll.mak test

若最終顯示 passed all tests 則說明生成的庫正確
e.安裝
安裝靜態(tài)庫:

nmake -f ms\nt.mak install

安裝動(dòng)態(tài)庫:

nmake -f ms\ntdll.mak install

編譯安裝完成后,會(huì)在E:\curl\openssl-1.0.2e\develop目錄下看到生成的相關(guān)文件夾
f.清楚上次編譯
清除上次靜態(tài)庫的編譯,以便重新編譯:

nmake -f ms\nt.mak clean

清除上次動(dòng)態(tài)庫的編譯,以便重新編譯:

nmake -f ms\ntdll.mak clean

參考:https://blog.csdn.net/mayue_web/article/details/83997969,非常詳細(xì)

2.編譯zlib

a.下載源碼
http://zlib.net/zlib-1.2.11.tar.gz
解壓后,在zlib根目錄下 命令行執(zhí)行
nmake -f win32/Makefile.msc

3.編譯libcurl

a.下載源碼
http://curl.haxx.se/download/curl-7.46.0.tar.bz2
b.拷貝所需的openssl與zlib相關(guān)庫與頭文件
.根據(jù)curl源代碼根目錄下winbuild目錄下BUILD.WINDOWS.txt的提示
在源代碼同級的目錄下建立deps文件夾
此時(shí)的目錄結(jié)構(gòu)如下圖(偽目錄

somedirectory\ |__curl-src | |_winbuild | |__deps|_ lib|_ include|_ bin

我這里的deps文件夾目錄是 E:\curl\deps
將編譯openssl時(shí)候,安裝目錄E:\curl\openssl-1.0.2e\develop\include下的
openssl夾拷貝到E:\curl\deps\include\目錄下;
將zlib源碼根目錄下的zconf.h、zlib.h和zutil.h拷貝到E:\curl\deps\include目錄下。
將E:\curl\openssl-1.0.2e\develop\lib目錄下的libeay32.lib和ssleay.lib拷貝到E:\curl\deps\lib目錄下;
將zlib源碼根目錄下的zlib.lib拷貝到E:\curl\deps\lib目錄下。
c.編譯libcurl
命令行進(jìn)入源代碼根目錄下 winbuild 目錄

nmake RTLIBCFG=static /f Makefile.vc mode=static VC=14 WITH_DEVEL=E:\curl\deps WITH_SSL=static ENABLE_SSPI=no ENABLE_IPV6=no DEBUG=no

參數(shù)詳細(xì)含義如下:

nmake /f Makefile.vc mode=<static or dll> <options>where <options> is one or many of:VC=<6,7,8,9,10,11,12,14> - VC versionsWITH_DEVEL=<path> - Paths for the development files (SSL, zlib, etc.)Defaults to sibbling directory deps: ../depsLibraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/Uncompress them into the deps folder.WITH_SSL=<dll or static> - Enable OpenSSL support, DLL or staticWITH_CARES=<dll or static> - Enable c-ares support, DLL or staticWITH_ZLIB=<dll or static> - Enable zlib support, DLL or staticWITH_SSH2=<dll or static> - Enable libSSH2 support, DLL or staticENABLE_SSPI=<yes or no> - Enable SSPI support, defaults to yesENABLE_IPV6=<yes or no> - Enable IPv6, defaults to yesENABLE_IDN=<yes or no> - Enable use of Windows IDN APIs, defaults to yesRequires Windows Vista or later, or installation from:http://www.microsoft.com/downloads/details.aspx?FamilyID=AD6158D7-DDBA-416A-9109-07607425A815ENABLE_WINSSL=<yes or no> - Enable native Windows SSL support, defaults to yesGEN_PDB=<yes or no> - Generate Program Database (debug symbols for release build)DEBUG=<yes or no> - Debug buildsMACHINE=<x86 or x64> - Target architecture (default is x86)Static linking of Microsoft's C RunTime (CRT): ============================================== If you are using mode=static nmake will create and link to the static build of libcurl but *not* the static CRT. If you must you can force nmake to link in the static CRT by passing RTLIBCFG=static. Typically you shouldn't use that option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and therefore rarely tested. When passing RTLIBCFG for a configuration that was already built but not with that option, or if the option was specified differently, you must destroy the build directory containing the configuration so that nmake can build it from scratch.Legacy Windows and SSL ====================== When you build curl using the build files in this directory the default SSL backend will be WinSSL (Windows SSPI, more specifically Schannel), the native SSL library that comes with the Windows OS. WinSSL in Windows <= XP is not able to connect to servers that no longer support the legacy handshakes and algorithms used by those versions. If you will be using curl in one of those earlier versions of Windows you should choose another SSL backend like OpenSSL.

3.驗(yàn)證

vs2015
添加好包含目錄 ,附加庫目錄, 附加依賴項(xiàng)后,預(yù)處理器添加上BUILDING_LIBCURL

// staticLibcurlTest.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。 //#include "stdafx.h" #include <iostream> #include <curl.h>using namespace std;/** * 一旦curl接收到數(shù)據(jù),就會(huì)調(diào)用此回調(diào)函數(shù) * buffer:數(shù)據(jù)緩沖區(qū)指針 * size:調(diào)試階段總是發(fā)現(xiàn)為1 * nmemb:(memory block)代表此次接受的內(nèi)存塊的長度 * userp:用戶自定義的一個(gè)參數(shù) */ size_t write_data(void* buffer, size_t size, size_t nmemb, void* userp) {static int current_index = 0;cout << "current:" << current_index++;cout << (char*)buffer;cout << "---------------" << endl;int temp = *(int*)userp; // 這里獲取用戶自定義參數(shù)return nmemb; }int main() {curl_global_init(CURL_GLOBAL_ALL); // 首先全局初始化CURLCURL* curl = curl_easy_init(); // 初始化CURL句柄if (NULL == curl){return 0;}int my_param = 1; // 自定義一個(gè)用戶參數(shù)// 設(shè)置目標(biāo)URLcurl_easy_setopt(curl, CURLOPT_URL, "https://api.vxxx/gettime");// 設(shè)置接收到HTTP服務(wù)器的數(shù)據(jù)時(shí)調(diào)用的回調(diào)函數(shù)curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);// 設(shè)置自定義參數(shù)(回調(diào)函數(shù)的第四個(gè)參數(shù))curl_easy_setopt(curl, CURLOPT_WRITEDATA, &my_param);// 執(zhí)行一次URL請求CURLcode res = curl_easy_perform(curl);// 清理干凈curl_easy_cleanup(curl);getchar();return 0; }

參考:
https://blog.csdn.net/fm0517/article/details/91822880
https://blog.csdn.net/huangyimo/article/details/80337496

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的在windows下,编译可访问https的libcurl静态库过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。