0

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. :)

5
Contributors
11
Replies
12
Views
8 Years
Discussion Span
Last Post by shankhaa
0

Where did you put libcurl.a ?

Where your -L option points to?

what do you mean by -L

0

-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.

0

-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?

0

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.

0

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

0

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

0

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.