用C在Mac上使用时的libcurl [英] LibCURL when used on Mac with C

查看:545
本文介绍了用C在Mac上使用时的libcurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想简单地使用libcurl的下载网站,我一直在使用这种code:

 的#include<&stdio.h中GT;
#包括LT&;卷曲/ curl.h>INT主要(无效)
{
  卷曲*卷曲;
  卷曲code资源;  卷曲= curl_easy_init();
  如果(卷曲){
    curl_easy_setopt(卷曲,CURLOPT_URL,http://google.com);
    RES = curl_easy_perform(卷曲);    / *总是清理* /
    curl_easy_cleanup(卷曲);
  }
  返回0;
}

和得到这个错误:

 未定义的符号:
   _curl_easy_perform,从引用:
      在_main ccGyMZQR.o
  _curl_easy_init,从引用:
      在_main ccGyMZQR.o
  _curl_easy_setopt,从引用:
      在_main ccGyMZQR.o
  _curl_easy_cleanup,从引用:
      在_main ccGyMZQR.o
    LD:符号(S)未找到
    collect2:劳工处返回1退出状态


解决方案

您需要链接到卷曲库。

如果你正在使用gcc,尝试使用编译


  

GCC -lcurl file.c中


这是指定你需要对libcurl的链接。

Basically, I'm trying to simply use libCURL to download a web site and I've been using this code:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}

And getting this error:

Undefined symbols:
   "_curl_easy_perform", referenced from:
      _main in ccGyMZQR.o
  "_curl_easy_init", referenced from:
      _main in ccGyMZQR.o
  "_curl_easy_setopt", referenced from:
      _main in ccGyMZQR.o
  "_curl_easy_cleanup", referenced from:
      _main in ccGyMZQR.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

解决方案

You need to link to the cURL library.

If you're using gcc, try compiling using

gcc -lcurl file.c

That specifies that you need to link against libcURL.

这篇关于用C在Mac上使用时的libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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