I got a snippet off the web of how to download a file from online in c++ console with the curl library. so I installed curl, and copied the code snippet, but it doesnt work. Can someone show me whats wrong?

#include <curl/curl.h>
#include <cstdio>
 
// link with libcurl. eg.
// g++ -Wall -std=c++98 -pedantic -Werror -lcurl -I /usr/local/include    -L /usr/local/lib
 
void get_page( const char* url, const char* file_name )
{
  CURL* easyhandle = curl_easy_init() ;
 
  curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
 
  std::FILE* file = std::fopen( file_name, "w" ) ;
  curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file ) ;
 
  curl_easy_perform( easyhandle );
 
  curl_easy_cleanup( easyhandle );
}
 
int main()
{
  get_page( "www.research.att.com/~bs/",
            "/tmp/stroustrup_home_page.html" ) ;
}

and heres the error:

[Linker error] undefined reference to `_imp__curl_easy_init'
[Linker error] undefined reference to `_imp__curl_easy_setopt'
[Linker error] undefined reference to `_imp__curl_easy_setopt'
[Linker error] undefined reference to `_imp__curl_easy_perform'
[Linker error] undefined reference to `_imp__curl_easy_cleanup'
ld returned 1 exit status

so does anyone know whats wrong? many thanks. :)

Where did you put libcurl.a ?

Where your -L option points to?

what do you mean by -L

-L /usr/local/lib

Is /usr/local/lib/libcurl.a a file or not?

If it isn't, you're digging in the wrong place.

-L /usr/local/lib

Is /usr/local/lib/libcurl.a a file or not?

If it isn't, you're digging in the wrong place.

i dont know if it exists or not. what i did was downloaded a devpack for curl, and it auto installed itself.

how can i find out?

Oh, so you're not on Linux using that comment as the command line then.

Project->settings
-> Add Include search path
-> Add library path
-> Add library name

> how can i find out?
Look in your d:\dev-c++ directory for an include and a lib directory.
They're probably in there somewhere.

Oh, so you're not on Linux using that comment as the command line then.

Project->settings
-> Add Include search path
-> Add library path
-> Add library name

> how can i find out?
Look in your d:\dev-c++ directory for an include and a lib directory.
They're probably in there somewhere.

ok. i added the libcurl.a file to my project, but when i compile it, it says that libcurl.a doesn't exist

Dunno,
Study the syntax used by your IDE for specifying paths and names for other libraries.

Dunno,
Study the syntax used by your IDE for specifying paths and names for other libraries.

can you say that alittle simpler? dont quite understand

I got a snippet off the web of how to download a file from online in c++ console with the curl library. so I installed curl, and copied the code snippet, but it doesnt work. Can someone show me whats wrong?

#include <curl/curl.h>
#include <cstdio>
 
// link with libcurl. eg.
// g++ -Wall -std=c++98 -pedantic -Werror -lcurl -I /usr/local/include    -L /usr/local/lib
 
void get_page( const char* url, const char* file_name )
{
  CURL* easyhandle = curl_easy_init() ;
 
  curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;
 
  std::FILE* file = std::fopen( file_name, "w" ) ;
  curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file ) ;
 
  curl_easy_perform( easyhandle );
 
  curl_easy_cleanup( easyhandle );
}
 
int main()
{
  get_page( "www.research.att.com/~bs/",
            "/tmp/stroustrup_home_page.html" ) ;
}

and heres the error:


so does anyone know whats wrong? many thanks. :)

I have the same problem and the same question. Anyone use CURL?

This article has been dead for over six months. Start a new discussion instead.