开发者

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();
    开发者_StackOverflowif(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:

Including libcurl in C project

And now I'm getting these Build errors:

Including libcurl in C project

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


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.


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.


For XCode 7, just right click on the project or group you want to put the lib in, then select Add Files to "Project Name"..., and finally find the libcurl.dylib in /usr/lib directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜