Po przeczytaniu trochę o cURL postanowiłem napisać program w C, używający tej biblioteki. Niby wszystko ładnie, program jednak się nie kompilował. Sprawdziłem więc, czy przykładowy program z oficjalnej strony uda się skompilować. Oto kod źródłowy:
Kod
#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, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
Potem piszę sobie:
$ gcc knights.c
I dostaję błąd:
/tmp/ccIrILAj.o: In function `main':
knights.c:(.text+0x9): undefined reference to `curl_easy_init'
knights.c:(.text+0x2c): undefined reference to `curl_easy_setopt'
knights.c:(.text+0x35): undefined reference to `curl_easy_perform'
knights.c:(.text+0x41): undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
To były tylko wywołania funkcji! Jakim więc cudem TO może nie działać?