Created
May 5, 2014 20:12
-
-
Save alghanmi/c5d7b761b2c9ab199157 to your computer and use it in GitHub Desktop.
cURL C++ Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <curl/curl.h> | |
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) | |
{ | |
((std::string*)userp)->append((char*)contents, size * nmemb); | |
return size * nmemb; | |
} | |
int main(void) | |
{ | |
CURL *curl; | |
CURLcode res; | |
std::string readBuffer; | |
curl = curl_easy_init(); | |
if(curl) { | |
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); | |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); | |
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); | |
res = curl_easy_perform(curl); | |
curl_easy_cleanup(curl); | |
std::cout << readBuffer << std::endl; | |
} | |
return 0; | |
} |
I'm getting this output
$ g++ main.cpp -lcurl
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0x51): undefined reference to `_imp__curl_easy_init'
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0x7b): undefined reference to `_imp__curl_easy_setopt'
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0x98): undefined reference to `_imp__curl_easy_setopt'
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0xb4): undefined reference to `_imp__curl_easy_setopt'
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0xc1): undefined reference to `_imp__curl_easy_perform'
C:\Users\Admin\AppData\Local\Temp\ccEeyCDI.o:cleopatra.cpp:(.text+0xd1): undefined reference to `_imp__curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this was the best explanation