由於linux平臺採用了libcurl,有一個程序移植到到windows平臺,再linux採用libcurl。在windows下準備也採用該庫。在網上搜索了幾位同行寫的,步驟上面有缺失。linux
本文將以詳細的步驟,介紹libcurl的編譯。git
下面是步驟:github
1. 下載源代碼,直接從github上clone倉庫,就能夠了。windows
git clone https://github.com/curl/curl.git服務器
2. 選擇版本ssh
我採用了版本: 7.56.0 (tag)curl
3. 生成工程函數
執行curl/projects文件下generate.bat,生成一個windows文件,文件夾下面有VS的工程,我選擇的VS14。ui
4. 打開curl-all.sln工程url
5. 選擇編譯的項目:
6. 咱們不須要OpenSSL 和 SSH2 兩個庫,我選擇LIB Release執行,執行成功了。
7. 編譯支持ssl的庫,再projects中有一個ReadMe.txt,咱們打開看一下。
The projects files also support build configurations that require third party dependencies such as OpenSSL, wolfSSL and SSH2. If you wish to support these, you will also need to download and compile those libraries as well.
若是須要支持他們,須要download這些特性呢,須要安裝而且編譯這些庫。文件的目錄結構以下:
8. 咱們接下來去github下載openssl 和 ssh2吧。注意,目錄結構要和curl在同一個文件夾下面。(github的服務器在老外,估計有時候下載速度有點慢,若是碰到了很慢的狀況,耐心等待一會。喝茶中....)
git clone https://github.com/openssl/openssl.git
git clone https://github.com/libssh2/libssh2.git
9. clone 完成,openssl 我採用了1.0.2 的版本, ssh2採用了1.9.0的版本
10. 執行curl/projects/build-openssl.bat的批處理腳本
Usage: build-openssl <compiler> <platform> [configuration] [directory]
build-openssl vc14 x64 release ../../openssl
11. 選擇編譯選項的類型
12. 執行結果查看,成功了。
13. 在VS中引用生成的庫。
#include <curl/curl.h>
#pragma comment(lib, "libcurl.lib")
直接引用,會報error LNK2019: 沒法解析的外部符號 __imp__curl_easy_init,該符號在函數 _main 中被引用 這個錯誤。
須要定義下面的兩個宏:
而後開始編譯,再也不報錯。