Including libcurl in project

2019-07-04 07:36发布

问题:

So I downloaded the zip file from the curl website. I copied the directory with all of the header files into my include directory. Including the curl.h works with no problems, however, when I go to actually call a function, suddenly my c++ app will no longer compile.

Here's the error I'm receiving:

 [Linker error] undefined reference to
 `curl_easy_init'

Here's the code:

#define CURL_STATICLIB
#include <curl/curl.h>
#include <string>
#include <iostream>
using namespace std;

int main() {
      string url = "http://www.google.com";
      cout << "Retrieving " << url << endl;

      // Our curl objects
      CURL *curl;
      CURLcode result;

      // Create our curl handle  
      curl = curl_easy_init();  

    system("pause");

    return 0;
}

It works fine if I comment out the curl=curl_easy_init() line.

According to the documentation this should work, as seen here.

Any ideas?

回答1:

you must link your program with the curl library

-L/path/of/curl/lib/libcurl.a (g++)

or add curl in your solution

Solution->properties->Link(ing) and add libcurl.lib


标签: c++ libcurl