1. 程式人生 > >windows平臺下libcurl庫編譯步驟

windows平臺下libcurl庫編譯步驟

關鍵詞:Windows,curl,ssl, visual c++ 2005

  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選擇你所想要的版本,
    d. 下載ActivePerl
    官網:

    http://www.activestate.com/activeperl/downloads
    請注意根據自己的系統版本【32,64】選擇不同的安裝包

  2. 編譯方法:

    a. 安裝activePerl
    直接雙擊安裝,用預設設定就可以了。
    b. 解壓所有的原始碼檔案,全部放在一個目錄下,比如我是c:\curl目錄下,目錄結構如下:

    curl
    |-----curl
    |-----openssl
    |-----zlib
    

    c. 編譯zlib
    從開始選單,選擇Microsoft Visual Studio 2005 > Visual Studio Tools > Visual Studio 2005 Command Prompt,如下圖:

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

    nmake -f win32/Makefile.msc OBJA=“inffast.obj” 過了一會兒就編譯成功。

    d. 編譯openssl
    將當前目錄切換到C:\curl\openssl-1.0.1f,如何輸入下面執行下面的命令:
    ms\32all.bat然後就開始了漫長的編譯,我這等了15分鐘才編譯好= =$

    e. 編譯curllib
    將當前目錄切換到curl的的目錄下C:\curl\curl-7.35.0\lib,然後依次輸入一下的命令:
    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,依次類推吧。
    編譯選項如下:

    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,我就選擇編譯了兩個靜態庫:

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

然後就是開始華麗麗的刷屏等待啦~~~
過了幾分鐘之後,就編譯好了,將C:\curl\curl-7.35.0\lib\會有debug-ssl-zlib和release-ssl-zlib目錄,拷貝到VS的工程目下,然後配置一下就可以使用了。

  1. CURL在windows下的編譯使用

    CURL的使用要注意幾點:

    3.1 使用CURL的工程依賴加libcurl.lib ws2_32.lib wldap32.lib

    3.2 工程加巨集CURL_STATICLIB

    3.3 debug版忽略LIBCMTD.lib,release版忽略LIBCMT.lib

參考資料:

http://blog.sina.com.cn/s/blog_62949ff40102x2wm.html
https://blog.csdn.net/hujkay/article/details/18986153
https://blog.csdn.net/diaoxuesong/article/details/78664663
https://blog.csdn.net/oilcode/article/details/45155101