在windows下,編譯可訪問https的libcurl靜態庫過程

1. 首先編譯openssl靜態庫

整個過程用的是 vs2015命令提示工具

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

a.配置編譯文件和模式
執行

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

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

ms\do_win64a.bat

若為Windows 32位系統,執行

ms\do_ms.bat

執行這一步之后,在ms目錄下會生成nt.mak和ntdll.mak兩個編譯配置文件
nt.mak 用于生成靜態lib庫
ntdll.mak 用于生成動態dll庫
c.編譯
靜態庫

nmake -f ms\nt.mak	

動態庫

nmake -f ms\ntdll.mak

d.測試
測試靜態庫:

 nmake -f ms\nt.mak test

測試動態庫:

 nmake -f ms\ntdll.mak test

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

nmake -f ms\nt.mak install

安裝動態庫:

nmake -f ms\ntdll.mak install

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

nmake -f ms\nt.mak clean

清除上次動態庫的編譯,以便重新編譯:

nmake -f ms\ntdll.mak clean

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

2.編譯zlib

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

3.編譯libcurl

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

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

我這里的deps文件夾目錄是 E:\curl\deps
將編譯openssl時候,安裝目錄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
命令行進入源代碼根目錄下 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

參數詳細含義如下:

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.驗證

vs2015
添加好包含目錄 ,附加庫目錄, 附加依賴項后,預處理器添加上BUILDING_LIBCURL

// staticLibcurlTest.cpp : 定義控制臺應用程序的入口點。
//#include "stdafx.h"
#include <iostream>
#include <curl.h>using namespace std;/**
* 一旦curl接收到數據,就會調用此回調函數
* buffer:數據緩沖區指針
* size:調試階段總是發現為1
* nmemb:(memory block)代表此次接受的內存塊的長度
* userp:用戶自定義的一個參數
*/
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;    // 這里獲取用戶自定義參數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;    // 自定義一個用戶參數// 設置目標URLcurl_easy_setopt(curl, CURLOPT_URL, "https://api.vxxx/gettime");// 設置接收到HTTP服務器的數據時調用的回調函數curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);// 設置自定義參數(回調函數的第四個參數)curl_easy_setopt(curl, CURLOPT_WRITEDATA, &my_param);// 執行一次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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/382421.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382421.shtml
英文地址,請注明出處:http://en.pswp.cn/news/382421.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Go語言爬蟲項目將結果寫入MySql數據庫

來源于Google資深工程師深度講解Go語言 package mainimport ("fmt""io/ioutil""net/http" )const url "http://www.zhenai.com/zhenghun"func main() {//發送get請求resp, err : http.Get(url)if err ! nil {panic(err)}//關閉通道d…

go語言學習路徑

個人記錄 go語言如何連接數據庫&#xff1a;增刪改查 Go語言爬蟲項目將結果寫入MySql數據庫 go語言急速入門

在windows上使用go編譯dll文件,供C++調用

C項目是win32的&#xff0c;所以go的編譯環境也要改成win32的 cmd下&#xff0c;修改環境變量&#xff1a; set GOARCH386 set CGO_ENABLED1 使用go env 查看是否生效參考&#xff1a;https://bbs.csdn.net/topics/394513992. 2. 安裝編譯環境 MinGW下載安裝gcc,g編譯器 參考&…

go語言急速入門

Go 語言極速入門1 - 環境搭建與最簡姿勢 Go 語言極速入門2 - 基礎語法 Go 語言極速入門3 - 內建容器 Go 語言極速入門4 - 面向對象 Go 語言極速入門5 - 面向接口 Go 語言極速入門6 - 閉包 Go 語言極速入門7 - 資源管理與錯誤處理 Go 語言極速入門8 - Goroutine Go 語言極速入門…

windows遠程桌面mstsc使用 代理

轉自 https://blog.csdn.net/bodybo/article/details/6638005

go語言掃描四位數可用域名

域名注冊查詢接口(API)的說明 原文出處 域名查詢 接口采用HTTP&#xff0c;POST&#xff0c;GET協議&#xff1a; 調用URL&#xff1a;http://panda.www.net.cn/cgi-bin/check.cgi 參數名稱&#xff1a;area_domain 值為標準域名&#xff0c;例&#xff1a;hichina.com 調用…

cmake構建工具 初步01

記錄下cmake學習過程&#xff0c;以后還會補充 單目錄單文件 demo1 目錄下只有一個a1.cpp, 如下圖 [rootlocalhost demo1]# tree . ├── a1.cpp └── CMakeLists.txt編寫CMakeLists.txt 1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)2 3 PROJECT(demo1)4 5 ADD_EXECUTABLE(d…

Mysql5.7后的password加密和md5

5.7之后 password函數舊版16位&#xff0c;新版41位&#xff0c;可用select password(‘123456’)查看。md5加密算法&#xff0c;只有16位和32位兩種 authentication_string 且5.7之后移除了password&#xff0c;它采用了新的算法 5.7之前 mysql> select user,host,pas…

用python寫的簡單的http文件服務器demo

import socket import os import re import time from multiprocessing import Processclass CHttpServer(object):"""Httpserver服務端類"""def __init__(self):self.m_serverSocket socket.socket(socket.AF_INET,socket.SOCK_STREAM)self.m_…

從《四驅兄弟》到“聯想中國”

《四驅兄弟》 小學的時候看過一個日本的動畫片叫四驅兄弟&#xff0c;里面就是一群小朋友代表國家各種比賽&#xff0c;其中讓我象比較深刻的是他把美國隊描述的非常邪惡&#xff0c;各種破壞別人的車子&#xff0c;通過卑鄙手段取得勝利。然后最后好像是正義戰勝邪惡的劇情還…

Mac SecureCRT解決中文亂碼

下載地址 https://xclient.info/s/navicat-premium.html#versions SecureCRT解決中文亂碼問題 在設置中設置為utf-8之后&#xff0c;還需要 $ sudo vi /etc/profile $打開文件&#xff0c;最后一行添加export LANGzh_CN.UTF-8

音視頻之使用sonic.cpp實現音頻倍速播放功能

sonic.cpp 是一個音頻處理庫&#xff0c;可以實現倍速播放。 如果單純通過修改pcm的采樣率來實現音頻倍速播放的話&#xff0c;就會出現聲音變調的情況。 以下是通過采集windows 虛擬聲卡獲取到的音頻數據&#xff0c; 我的聲卡采樣率是44100次/秒&#xff0c;audio_buffer_si…

SecurtCRT連接服務器自動斷開

mac Terminal-->Anti-idle-->send protocol NO-OP 60勾中

位圖原理、代碼實現及應用實例

位圖的原理&#xff1a; 在位圖中采用比特位表示對應的元素存在或者不存在 0&#xff1a;不存在 1&#xff1a;存在例如一個int整數有32個比特位可以表示0-31個整數。 再舉一個例子 存入的數字為8988 首先&#xff1a; 8988/32 280 其次&#xff1a; 8988%32 28 再來一個例…

通過修改注冊表,實現網頁鏈接中的私有協議啟用本地exe進程

私有協議為 coffeeclass://xxxxxx.mp4 注冊表如下 Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\coffeeclass] "coffeeClass Protocol" "URL Protocol"""[HKEY_CLASSES_ROOT\coffeeclass\DefaultIcon] "D:\\Program Files (x…

布隆過濾器的原理、應用場景和源碼分析實現

原理 布隆過濾器數據結構 布隆過濾器是一個 bit 向量或者說 bit 數組&#xff0c;長這樣&#xff1a; 如果我們要映射一個值到布隆過濾器中&#xff0c;我們需要使用多個不同的哈希函數生成多個哈希值&#xff0c;并對每個生成的哈希值指向的 bit 位置 1。 例如針對值 “baid…

判斷一個數字是否存在于某一個數據之中

哈希表 這個沒啥說的&#xff0c;后面補充 位圖 https://blog.csdn.net/csdn_kou/article/details/95337121 布隆過濾器 哈希表位圖 https://blog.csdn.net/csdn_kou/article/details/95371085

根據語句自動生成正則表達式

自動生成 http://www.txt2re.com 速查手冊 https://www.jb51.net/shouce/jquery/regexp.html

免密登錄堡壘機和服務器

免密登錄堡壘機 安裝oathtool和sshpass 這兩個文件安裝比較耗費時間&#xff01; brew install oath-toolkit brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb免密登錄堡壘機 書寫shell腳本 #!/usr/bin/env bash …