因為linux平台采用了libcurl,有一個程序移植到到windows平台,再linux采用libcurl。在windows下准備也采用該庫。在網上搜索了幾位同行寫的,步驟上面有缺失。
本文將以詳細的步驟,介紹libcurl的編譯。
下面是步驟:
1. 下載源代碼,直接從github上clone倉庫,就可以了。
git clone https://github.com/curl/curl.git
2. 選擇版本
我采用了版本: 7.56.0 (tag)
3. 生成工程
執行curl/projects文件下generate.bat,生成一個windows文件,文件夾下面有VS的工程,我選擇的VS14。

4. 打開curl-all.sln工程

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 中被引用 這個錯誤。
需要定義下面的兩個宏:

然后開始編譯,不再報錯。

