爲了方便安裝,在D盤根目錄下新建一個名爲libcurl-ssl的文件夾,將下載的三個壓縮包解壓到該文件夾。
在 curl-7.54.0 -> lib 下新建文件夾openssl用來存放openssl的頭文件。html
打開安裝包,選擇Modify默認安裝或Repair修改安裝路徑均可以api
這是最麻煩、最容易出錯的一環了,由於他沒有項目文件,只能經過命令行來編譯。安全
等待差很少五分鐘,只要不出現「stop」,安全地執行到結束,就算成功。
一旦中間出了差錯,最好是把文件夾也刪了,從新解壓、配置編譯,若是你留有編譯失敗的半成品,它可能會告訴你「沒法解析XXX」。服務器
將 openssl-1.0.2k -> inc32 -> openssl 全部的.h 和 openssl-1.0.2k -> out32dll 的 libeay32.lib、libeay32.dll、ssleay32.lib、ssleay32.dll 一塊兒複製到 curl-7.54.0 -> lib -> openssl 中curl
編譯平臺選擇 DLL Debug - DLL OpenSSL函數
在編譯成功後 curl-7.54.0 -> build -> Win32 -> VC14 -> DLL Debug - DLL OpenSSL 文件夾中會生成有 libcurld.dll 和 libcurld.lib(注意名字不是libcurl)。工具
例如建立的項目文件夾位於 D: -> LibcurlTest,編譯版本爲debug X86。測試
#include "stdafx.h" #include "../include/curl/curl.h" #pragma comment(lib,"../lib/debug/libcurld.lib") int main() { CURL *curl; CURLcode res; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, true); curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_easy_cleanup(curl); } system("pause"); return 0; }
運行結果:在控制檯中顯示 https://www.baidu.com 網頁源碼,若是沒有OpenSSL的編譯和連接,是不能訪問https的。可是顯示中文部分是亂碼,本人水平有限,認爲這是C++輸出的問題,我將源碼保存成txt打開是沒問題的。ui
注:本文整理修改自互聯網。url