简体   繁体   中英

Including libcurl in C project

This is my very first C program and I'm using this example libcurl code from their website:

#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;
}

So in xcode I created a "group" called it curl and added all the files in the curl directory: 在此输入图像描述

And now I'm getting these Build errors: 在此输入图像描述

What am I doing wrong? Any advice would help, thanks!

For Xcode 4.5:

  1. Click on the project in the left pane.
  2. Click on the target.
  3. Go to the "Build Phases" section.
  4. Under "Link Binary with Libraries", click the plus sign.
  5. From there you should be able to search for "libcurl.dylib".

Now when you build it should be able to link to the library.

Mac OS X comes with a copy of libcurl, so your application doesn't need its own copy.

You didn't mention the version of Xcode you're using. The following applies to 3.2, but may not work in 4.

To use the version of libcurl provided by the system, go to Project , then Add To Project . In the dialog that comes up, type /usr/lib and press enter. Find libcurl.dylib in the list of files and click Add .

对于XCode 7,只需右键单击要放入lib的项目或组,然后选择Add Files to "Project Name"... ,最后在/usr/lib目录中找到libcurl.dylib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM