问题
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