天天看點

在Windows上編譯最新的CURL,含有zlib,openssl

最近,從網上下載下傳了一個curl庫,使用時各種報錯,都無法啟動,于是幹脆就直接自己編譯了。

    1. 準備工作

      a. 下載下傳zlib

          zlib可以使得HTTP請求支援gzip壓縮,其位址如下:

         官網:http://zlib.net/

         下載下傳位址:http://zlib.net/zlib-1.2.8.tar.gz

     b. 下載下傳openssl

          opensll使用與支援SSL,例如HTTPS的請求。

         官網:http://www.openssl.org

          下載下傳位址:http://www.openssl.org/source/openssl-1.0.1f.tar.gz

     c. 下載下傳curl

          官網:http://curl.haxx.se

          下載下傳位址:在http://curl.haxx.se/download.html選擇你所想要的版本,我這兒選用最新的7.35.0版本 [http://curl.haxx.se/download/curl-7.35.0.tar.gz]

    d. 下載下傳ActivePerl

          官網:http://www.activestate.com/activeperl/downloads

          請注意根據自己的系統版本【32,64】選擇不同的安裝包【連結失效時用迅雷可下載下傳】

         下載下傳位址:http://downloads.activestate.com/ActivePerl/releases/5.16.0.1600/ActivePerl-5.16.0.1600-MSWin32-x86-295879.msi

          X64下載下傳位址:http://downloads.activestate.com/ActivePerl/releases/5.16.0.1600/ActivePerl-5.16.0.1600-MSWin32-x64-295879.msi

    編譯方法:

      a. 安裝activePerl

         直接輕按兩下安裝,用預設設定就可以了。

      b. 解壓所有的源碼檔案,全部放在一個目錄下,比如我是房子c:\curl目錄下,目錄結構如下:

在Windows上編譯最新的CURL,含有zlib,openssl

      c. 編譯zlib

          從開始菜單,選擇Microsoft Visual Studio 2005 > Visual Studio Tools > Visual Studio 2005 Command Prompt,如下圖:

在Windows上編譯最新的CURL,含有zlib,openssl

     之後會彈出一個CMD視窗,切換到zlib的目錄下C:\curl\zlibxxx,然後輸入:

在Windows上編譯最新的CURL,含有zlib,openssl

nmake -f win32/Makefile.msc OBJA="inffast.obj"  

在Windows上編譯最新的CURL,含有zlib,openssl

  過了一會兒就編譯成功。

   2. 編譯openssl

     将目前目錄切換到C:\curl\openssl-1.0.1f,如何輸入下面執行下面的指令:

     ps:請不要直接打開cmd用vs自帶的指令行工具

在Windows上編譯最新的CURL,含有zlib,openssl

ms\32all.bat  

然後就開始了漫長的編譯,我這等了15分鐘才編譯好= =$

在Windows上編譯最新的CURL,含有zlib,openssl

  3. 編譯curllib

    将目前目錄切換到curl的的目錄下C:\curl\curl-7.35.0\lib,然後依次輸入一下的指令:

在Windows上編譯最新的CURL,含有zlib,openssl

set OPENSSL_PATH=..\..\openssl-1.0.1f  

set ZLIB_PATH=..\..\zlib-1.2.8  

nmake -f Makefile.vc8  CFG=release-dll-zlib-dll  

注意 Makefile.vc6是VC6.0的版本,VC8是VC2005,VC9是VS2008,依次類推吧。

CFG是配置編譯結果選項,其具體内容如下:

在Windows上編譯最新的CURL,含有zlib,openssl

Usage: nmake /f makefile.vc6 CFG=<config> <target>  

where <config> is one of:  

release                      - release static library  

release-ssl                  - release static library with ssl  

release-zlib                 - release static library with zlib  

release-ssl-zlib             - release static library with ssl and zlib  

release-ssl-ssh2-zlib        - release static library with ssl, ssh2 and zlib  

release-ssl-dll              - release static library with dynamic ssl  

release-zlib-dll             - release static library with dynamic zlib  

release-ssl-dll-zlib-dll     - release static library with dynamic ssl and dynamic zlib  

release-dll                  - release dynamic library  

release-dll-ssl-dll          - release dynamic library with dynamic ssl  

release-dll-zlib-dll         - release dynamic library with dynamic zlib  

release-dll-ssl-dll-zlib-dll - release dynamic library with dynamic ssl and dynamic zlib  

debug                        - debug static library  

debug-ssl                    - debug static library with ssl  

debug-zlib                   - debug static library with zlib  

debug-ssl-zlib               - debug static library with ssl and zlib  

debug-ssl-ssh2-zlib          - debug static library with ssl, ssh2 and zlib  

debug-ssl-dll                - debug static library with dynamic ssl  

debug-zlib-dll               - debug static library with dynamic zlib  

debug-ssl-dll-zlib-dll       - debug static library with dynamic ssl and dynamic zlib  

debug-dll                    - debug dynamic library  

debug-dll-ssl-dll            - debug dynamic library with dynamic ssl  

debug-dll-zlib-dll           - debug dynamic library with dynamic zlib1  

debug-dll-ssl-dll-zlib-dll   - debug dynamic library with dynamic ssl and dynamic zlib  

<target> can be left blank in which case all is assumed  

Makefile.vc8(501) : fatal error U1050: please choose a valid configuration "rele  

ase-dll-ssl-dll-zlib-dll "  

Stop.  

大家可以根據自己的需要編譯不同的DLL和lib,我就選擇編譯了兩個靜态庫:

在Windows上編譯最新的CURL,含有zlib,openssl

nmake -f Makefile.vc8  CFG=release-ssl-zlib  

nmake -f Makefile.vc8  CFG=debug-ssl-zlib  

在Windows上編譯最新的CURL,含有zlib,openssl

然後就是開始華麗麗的刷屏等待啦~~~

    過了幾分鐘之後,就編譯好了,将C:\curl\curl-7.35.0\lib\會有debug-ssl-zlib和release-ssl-zlib目錄,拷貝到VS的工程目下,然後配置一下就可以使用了。

繼續閱讀