在项目中包含libcurl [英] Including libcurl in project

查看:237
本文介绍了在项目中包含libcurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从curl网站下载了zip文件。我将所有头文件的目录复制到我的include目录中。包括curl.h的工作没有问题,但是,当我去实际调用一个函数,突然我的c ++应用程序将不再编译。



这里是错误我' m接收:

  [链接器错误]未定义引用
`curl_easy_init'

以下是代码:

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

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

//我们的curl对象
CURL * curl;
CURLcode result;

//创建我们的curl句柄
curl = curl_easy_init();

系统(pause);

return 0;
}



如果我注释掉curl = curl_easy_init / p>

根据文档,这应该可以工作,

p>您必须将程序与curl库链接

  -L / path / of / curl / lib / libcurl.a 


$ b <$>

Solution-> properties->链接(ing)并添加libcurl.lib


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?

解决方案

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

这篇关于在项目中包含libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆