windows VS2019配置libcurl


轉載來自:https://blog.csdn.net/DaSo_CSDN/article/details/77587916

整合了下

自己的安裝過程

下載地址:https://curl.se/download.html

 

 

 解壓,並進入文件夾,運行buildconf.bat。

 

 


本文以編譯x64為例
在開始菜單中找到Visual Studio 2017/2019文件夾,編譯64位則右擊x64 Native Tools Command Prompt for VS 2017/2019,編譯32位則右擊x86 Native Tools Command Prompt for VS 2017/2019,選擇Run as administrator。

 

 


進入curl文件夾中的winbuild文件夾。

 

 


VS2017/2019+x64+靜態編譯:

輸入nmake /f Makefile.vc mode=static VC=15 MACHINE=x64 DEBUG=no。
如需動態編譯,將mode=static改為mode=dll。(本文僅演示靜態編譯,同時curl官方也不建議使用動態編譯)
如需編譯為x86,將MACHINE=x64改為MACHINE=x86。
如需編譯為debug版,將DEBUG=no改為DEBUG=yes。
如果你是VS2017且未更新到最新版,VC=15建議改為VC=14。
更詳細的編譯指令及說明可以打開winbuild文件夾中的BUILD.WINDOWS.txt查看。

 

 

 


回車,等待編譯完成,關閉控制台界面。

生成這個

 

 配置vs

添加inclue  和lib

 

 

在鏈接器輸入 加入

 

 

libcurl_a.lib
Ws2_32.lib
Wldap32.lib
winmm.lib
Crypt32.lib
Normaliz.lib
本文使用了靜態編譯且沒有編譯debug版libcurl,所以直接在Configurations: All Configurations中將Runtime Library選擇為/MD。
如果編譯了debug版libcurl,請分別在Configurations: Debug中選擇/MDd、Configurations: Release中選擇/MD。
如果使用了動態編譯,則為/MTd和/MT。

測試

#include <curl/curl.h>    

int main(int argc, char* argv[]) {
    CURL *curl = 0;
    CURLcode res;
    curl = curl_easy_init();
    if (curl != 0) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
        
        //www.baidu.com 可能會跳轉,所以設置為跟隨跳轉
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        
        //發出請求
        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            //輸出可能是亂碼,因為沒配置UTF-8
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));        
        }
        
        //清理工作
        curl_easy_cleanup(curl);
    }

    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM