We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,414 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Using libcurl to download files in Windows

Hi!

My problems are more of porting a code to Windows, than the code itself. I need to download a file from a URL ( http://127.0.0.1/img.jpg ) and store it in a local file.

I think I've screwed up the setting up of the libcurl libraries. I am using Visual Studio 2008 as my IDE.

I first downloaded the zipped file with the libraries. I downloaded the file from here:
http://www.gknw.net/mirror/curl/win32/curl-7.20.0-devel-mingw32.zip
The description on the libcurl site said:
"This package is type libcurl This is a pure binary libcurl package, possibly including header files and documentation, but without the command line tool and other cruft. If you want libcurl for a program that uses libcurl, this is most likely the package you want."
Which fits in to what I want to do.

In my Visual Studio options, I added the libcurl folder in the 'include' path. I also added the bin folder (with all the .dll files) to my 'libraries' path.

I ran the following code:

#include <iostream>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
using namespace std;
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) 
{
    size_t written = fwrite(ptr, size, nmemb, stream);
    return written;
}

int downloader(string url)
{
    CURL *curl;
    FILE *fp;
    curl = curl_easy_init();
    return 0;
}

However, when I build the code, I get the following linking error:

error LNK2001: unresolved external symbol __imp__curl_easy_init
fatal error LNK1120: 1 unresolved externals

So, I next went and added all the dll's in the bin folder in the dependencies (Properties -> Linker -> Input-> Additional Dependencies).
(I could not find .lib files anywhere.)

Now when I compile it, I get the following error:

\C:\Program Files\libcurl\bin\libcurl.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2B8

Any idea what's the problem?

2
Contributors
1
Reply
9 Hours
Discussion Span
3 Years Ago
Last Updated
2
Views
kedarm
Newbie Poster
10 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

> In my Visual Studio options
Well there's your problem!

You downloaded MinGW libraries, not Visual Studio libraries.

Try here http://curl.haxx.se/download.html

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,875
Solved Threads: 953
Skill Endorsements: 27

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0596 seconds using 2.68MB