Including libcurl in project

只谈情不闲聊 提交于 2019-12-12 16:06:14

问题


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


来源:https://stackoverflow.com/questions/1669511/including-libcurl-in-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!