Libcurl 靜態編譯

來源:互聯網
上載者:User
Libcurl 靜態編譯 一、準備 curl原始碼下載,當前使用【curl-curl-7_53_1.zip】版本,編譯器使用VS2015 二、編譯 開啟VS2015 開發人員命令提示,並CD進入 curl-curl-7_53_1/winbuild/ 目錄 VS產生代碼的時候有一個運行庫選項(項目屬性 - 配置屬性 - C/C++ - 代碼產生 - 運行庫)/MT和/MD(/MTd和/MDd是對應的debug版本)
nmake /f Makefile.vc mode=static VC=14 RTLIBCFG=static

就是說你編譯時間如果加了RTLIBCFG=static這個選項,就相當於編譯了/MT版本的libcurl,否則是/MD版本的 完成編譯後libcurl靜態庫會出現在builds目錄下包括標頭檔和libcurl_a.lib,我們需要的是builds/libcurl-vc14-x86-release-static下面的include和lib兩個檔案夾 三、配置選項

nmake /f Makefile.vc mode=<static or dll> <options>where <options> is one or many of:  VC=<6,7,8,9,10,11,12,14>     - VC versions  WITH_DEVEL=<path>            - Paths for the development files (SSL, zlib, etc.)                                 Defaults to sibbling directory deps: ../deps                                 Libraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/                                 Uncompress them into the deps folder.  WITH_SSL=<dll or static>     - Enable OpenSSL support, DLL or static  WITH_MBEDTLS=<dll or static> - Enable mbedTLS support, DLL or static  WITH_CARES=<dll or static>   - Enable c-ares support, DLL or static  WITH_ZLIB=<dll or static>    - Enable zlib support, DLL or static  WITH_SSH2=<dll or static>    - Enable libSSH2 support, DLL or static  ENABLE_SSPI=<yes or no>      - Enable SSPI support, defaults to yes  ENABLE_IPV6=<yes or no>      - Enable IPv6, defaults to yes  ENABLE_IDN=<yes or no>       - Enable use of Windows IDN APIs, defaults to yes                                 Requires Windows Vista or later, or installation from:                                 https://www.microsoft.com/downloads/details.aspx?FamilyID=AD6158D7-DDBA-416A-9109-07607425A815  ENABLE_WINSSL=<yes or no>    - Enable native Windows SSL support, defaults to yes  GEN_PDB=<yes or no>          - Generate Program Database (debug symbols for release build)  DEBUG=<yes or no>            - Debug builds  MACHINE=<x86 or x64>         - Target architecture (default is x86)
精簡配置
nmake /f Makefile.vc mode=static VC=14 RTLIBCFG=static ENABLE_IPV6=no ENABLE_WINSSL=no ENABLE_SSPI=no
四、注意事項 注意靜態庫路徑和檔案名稱。 調用項目注意代碼產生模式為 MT。 增加ws2_32.lib,wldap32.lib 解決tcp通訊問題

添加預定義宏BUILDING_LIBCURLHTTP_ONLY,解決extern函式宣告問題,否則是動態庫函數名稱。

不知道為啥使用CURL_STSTICLIB宏不行,版本問題。

如果項目使用VS2013編譯,使用vs2015調用會出現以下錯誤,則要使用對應VS版本編譯libcurl源碼。(VC12對應vs2013 ,VC14對應VS2015)。

error LNK2019: 無法解析的外部符號 __iob_func 五、XP下編譯庫問題以及解決方案 照上述方法在win7以及以上系統版本中使用不會有問題,但是在XP系統下就會出現依賴庫的問題。
彈出缺少 normaliz.dll庫提示,而導致程式無法開啟 即使添加了normaliz.dll庫,也會出現介面定位錯誤。 其根本原因還是libcurl中調用的兩個windows函數:IdnToUnicode, IdnToAscii封裝在normaliz.dll中,而這個庫一開始並不是為Windows XP準備的,只是後來在SP2以後才有的。 解決方案:
修改CURL_FOLDER\lib\idn_win32.c源碼並重新編譯。
參考連結:http://www.cnblogs.com/passedbylove/p/5979927.html 進行到這步,然而在xp下依然會出現問題:libcurl在XP調用報GetTickCount64未找到的解決辦法

解決方案連結:http://blog.csdn.net/he_fly/article/details/53116180

【根據以上的步驟總結】 1.修改libcurl庫在CURL_FOLDER/lib/目錄下的idn_win32.cconfig-win32.h源碼。 2.編譯libcurl庫,完整的編譯命令如下:

nmake /f Makefile.vc mode=static VC=14 RTLIBCFG=static ENABLE_IPV6=no ENABLE_WINSSL=no ENABLE_SSPI=no ENABLE_IDN=no

ENABLE_IDN=no 即:不使用windows原始庫,產生庫大小也會減小。如果源碼沒有改動,按此方式產生的庫無法再工程項目中編譯通過。 參考連結 http://www.cnblogs.com/jkcx/p/6406706.html http://www.cnblogs.com/passedbylove/p/5979927.html http://blog.csdn.net/he_fly/article/details/53116180 編譯庫下載 http://download.csdn.net/download/amosfeng/10041408

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.