Curl programming in C
Have you ever used curl or wget on the command line? If not, check what is curl? Both curl and wget are useful command line tools to download a page. Using these tools you can download a whole website to your desktop. Curl can be also be used to post data to a website. Curl is command line tool making use of the libcurl library. libcurl library is used to download or upload web pages. It is a full fledged library with many capabilities.
For curl programming, you must include the curl header files in your program: curl/curl.h
#include <stdio.h>
#include <curl/curl.h>
int main()
{
CURL *curl;
curl = curl_easy_init();
/*
* Add your processing
*/
curl_easy_cleanup(curl);
}
Now if you compile this program in the following way
gcc curl.c
You may probably end up having the following error
Undefined symbols:
"_curl_easy_cleanup", referenced from:
_main in ccCyxU7X.o
"_curl_easy_init", referenced from:
_main in ccCyxU7X.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
This is because the libcurl library is not included by default. So to compile and link the libcurl library, you must make use of -l option of gcc which helps in dynamic linking of the libraries
gcc curl.c -l curl
Now your program will be properly compiled and linked
Comments:
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=9ce36e64-39c4-4944-a986-279b4ff401cb)