Sep 3, 2015 at 12:30pm UTC
Hi people, I'm trying to use libcurl to make a basic get request, but I can't even compile the project.
This is the code I am using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;
string data;
size_t writeCallback(char * buf, size_t size, size_t nmemb, void * up)
{
for (int c = 0; c<size*nmemb; c++)
{
data.push_back(buf[c]);
}
return size*nmemb;
}
int main()
{
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL); //pretty obvious
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://www.cplusplus.com" );
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_perform(curl);
cout << endl << data << endl;
cin.get();
curl_easy_cleanup(curl);
curl_global_cleanup();
system("pause" );
return 0;
}
And I'm getting this errors:
http://puu.sh/jYsfj/e35d6da8c6.png
Thanks in advance for any tips/suggestions!!
Last edited on Sep 3, 2015 at 12:40pm UTC
Sep 3, 2015 at 12:35pm UTC
have you check if curl != NULL ?
Sep 3, 2015 at 12:39pm UTC
How can I check that? I can't debug the program because it doesn't compile.
Sep 3, 2015 at 12:46pm UTC
Did you link the library ? I guess not . You should have a .lib and a .dll ,
add this precompiled instruction at the begginning
#pragma comment(lib , "THENAMEOFTHELIB.lib")
do not forget to add the extension .
If the lib is not in the same directory , then in the project properties , you should add the directory in the libraries directories .
Once that done , normally you should be able to compile , but you might get an error at launch saying that it could not find SOMENAME.dll .
For this , go to project properties and set the environment like so PATH=%PATH%;THEDLLDIRECTORY;
do not forget the semicolon at the end.
But you might as well copy the dll (s) to the exe dir .
Try that and reply if nothing worked out .
Sep 3, 2015 at 12:56pm UTC
Ok you were right, it compiled and now it's giving me the missing dll error. I added it in Linker -> Input -> Additional Dependencies, but now I am getting this error:
error LNK1181: cannot open input file '.obj'
Sep 3, 2015 at 1:08pm UTC
Remove the additionnal dependency and copy the dll to the same dir of the exe , just to see. And Rebuild
Sep 3, 2015 at 1:15pm UTC
Well, I added #pragma comment(lib , "libcurldll.a")
in the code, and this made the program compiling. But when I start it it tells me I need "libcurl.dll", and if I rename it, it tells me it's not made for windows.
Sep 3, 2015 at 1:22pm UTC
then you might miss a dll . Try to download it and put it in your exe dir .
Sep 3, 2015 at 1:23pm UTC
I downloaded the dll from the web and now it's working, thanks a lot for your help!!
Is there any way I can "hide" the dll in my program, so it's just one file?
Sep 3, 2015 at 1:25pm UTC
no... but can create a folder called bin for dlls