簡體   English   中英

在C項目中包含libcurl

[英]Including libcurl in C project

這是我的第一個C程序,我在他們的網站上使用這個示例libcurl代碼:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://google.com/");

#ifdef SKIP_PEER_VERIFICATION
        /*
         * If you want to connect to a site who isn't using a certificate that is
         * signed by one of the certs in the CA bundle you have, you can skip the
         * verification of the server's certificate. This makes the connection
         * A LOT LESS SECURE.
         *
         * If you have a CA cert for the server stored someplace else than in the
         * default bundle, then the CURLOPT_CAPATH option might come handy for
         * you.
         */ 
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif

#ifdef SKIP_HOSTNAME_VERFICATION
        /*
         * If the site you're connecting to uses a different host name that what
         * they have mentioned in their server certificate's commonName (or
         * subjectAltName) fields, libcurl will refuse to connect. You can skip
         * this check, but this will make the connection less secure.
         */ 
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif

        res = curl_easy_perform(curl);

        /* always cleanup */ 
        curl_easy_cleanup(curl);
    }
    return 0;
}

所以在xcode中我創建了一個名為curl的“組”並添加了curl目錄中的所有文件: 在此輸入圖像描述

現在我收到這些Build錯誤: 在此輸入圖像描述

我究竟做錯了什么? 任何建議都會有所幫助,謝謝!

對於Xcode 4.5:

  1. 單擊左窗格中的項目。
  2. 單擊目標。
  3. 轉到“構建階段”部分。
  4. 在“Link Binary with Libraries”下,單擊加號。
  5. 從那里你應該能夠搜索“libcurl.dylib”。

現在,當你構建它應該能夠鏈接到庫。

Mac OS X附帶了libcurl的副本,因此您的應用程序不需要自己的副本。

你沒有提到你正在使用的Xcode版本。 以下內容適用於3.2,但可能不適用於4。

要使用系統提供的libcurl版本,請轉到“ Project ,然后選擇“ Add To Project 在出現的對話框中,鍵入/usr/lib並按Enter鍵。 在文件列表中找到libcurl.dylib ,然后單擊“ Add

對於XCode 7,只需右鍵單擊要放入lib的項目或組,然后選擇Add Files to "Project Name"... ,最后在/usr/lib目錄中找到libcurl.dylib

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM