Включение libcurl в C-проект - PullRequest
2 голосов
/ 26 апреля 2011

Это моя самая первая программа на 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: enter image description here

А теперь я получаю следующие ошибки сборки: enter image description here

Что я делаю не так?Любой совет поможет, спасибо!

Ответы [ 3 ]

4 голосов
/ 08 января 2013

Для Xcode 4.5:

  1. Нажмите на проект в левой панели.
  2. Нажмите на цель.
  3. Перейдите в раздел «Фазы сборки».
  4. В разделе «Связать двоичные файлы с библиотеками» нажмите знак плюса.
  5. Оттуда вы сможете найти «libcurl.dylib».

Теперь при сборке он сможет ссылаться на библиотеку.

4 голосов
/ 26 апреля 2011

Mac OS X поставляется с копией libcurl, поэтому вашему приложению не требуется собственная копия.

Вы не упомянули версию Xcode, которую вы используете. Следующее относится к 3.2, но может не работать в 4.

Чтобы использовать версию libcurl, предоставленную системой, перейдите на Project, затем Add To Project. В появившемся диалоговом окне введите /usr/lib и нажмите ввод. Найдите libcurl.dylib в списке файлов и нажмите Add.

1 голос
/ 30 декабря 2015

Для XCode 7, просто щелкните правой кнопкой мыши проект или группу, в которую вы хотите поместить библиотеку, затем выберите Add Files to "Project Name"... и, наконец, найдите каталог libcurl.dylib в /usr/lib.

...