LibCURL when used on Mac with C

两盒软妹~` 提交于 2019-12-07 14:13:31

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/4719071/libcurl-when-used-on-mac-with-c

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