Friday, December 16, 2011

How to use libcurl in C/C++

libcurl
Newer languages such as Java and newer scripting languages such as Python come with good libraries to download files and do online work. A good way to download files using C/C++ is to download and install the libcurl library.
First run 'curl-config --libs' to see if you have the library '-libcurl'
search for the package: 'apt-cache search libcurl'
install the package: 'sudo apt-get install libcurl4-nss-dev'
check to see if you have the package again
Next, go to http://curl.haxx.se/libcurl/c/simple.html. Copy and paste the code, save as 'simple.c' Change the "http://example.com" to something you want.
Compile your code: 'gcc simple.c -lcurl -o simple.out'
Run the code: './simple.out'

Output of (http://www.google.com/):
http://curl.haxx.se/libcurl/c/simple.html

No comments:

Post a Comment

Please make suggestions :)