Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including libcurl in project

Tags:

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?

like image 613
Cory Dee Avatar asked Nov 03 '09 19:11

Cory Dee


1 Answers

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
like image 59
Nadir SOUALEM Avatar answered Nov 15 '22 07:11

Nadir SOUALEM