cURL / Mailing Lists / curl-library / Single Mail

curl-library

Howto: Use libcurl with MinGW.

From: jason cipriani <jason.cipriani_at_gmail.com>
Date: Sat, 10 Feb 2007 03:59:40 -0500

I wanted to use libcurl with mingw; but for some reason the mingw
binary is missing off the download page (use the wizard, the file
isn't found). Also I searched quickly and saw that a number of people
had problems with libcurl "not working" under mingw. Here is how I got
it to work on mingw using the MSVC version -- it's very simple so I
thought I'd share. Do this if you want to use libcurl on mingw and you
are having problems.

DEVELOPMENT SETUP:

1) Visit the download wizard (http://curl.haxx.se/dlwiz/?type=devel)
and download the Win32 MSVC version of libcurl. I did not need SSL so
I got the version without it. This little guide doesn't cover SSL.

2) Visit the zlib download page
(http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=16861)
and download the current zlib *-bin package for Win32. You'll need to
do this even if you have mingw zlib already installed. If that link is
broken, you can access this page by going to the libcurl download
page, going all the way to the bottom and clicking on the GnuWin32
project page link, and picking zlib from the list.

3) Install libcurl by hand. They're both easy. For libcurl open up the
zip file. Copy the libcurl.dll to somewhere in your static link path
(perhaps /usr/local/lib) (you do not need the .lib file). Copy the
contents of the include directory to your include path (perhaps
/usr/local/include). That's almost it, except...

4) To get applications to compile with curl.h using mingw gcc you have
to edit one small thing in curl.h. Open up include_path/curl/curl.h.
There's no such thing as a "long long" in ISO C++. Go down to around
line 94 (where all the curl_off_t typedefs are) and find the "gcc on
windows or watcom" comment:

#if (defined(__GNUC__) && defined(WIN32)) || defined(__WATCOMC__)
  /* gcc on windows or Watcom */
  typedef long long curl_off_t;
#define CURL_FORMAT_OFF_T "%I64d"

I'm guessing, based on the format string, that it wants a 64-bit
signed integer, so change that little bit of code to:

#if (defined(__GNUC__) && defined(WIN32)) || defined(__WATCOMC__)
  /* gcc on windows or Watcom */
#include <stdint.h>
  typedef int64_t curl_off_t;
#define CURL_FORMAT_OFF_T "%I64d"

Note the stdint.h include. Incidently, to rant, I don't really get why
there's all this mess in this header anyway... most of this stuff is
already handled in system headers (like the int64_t), etc, and it
seems like it would be a bit more sane to just check for the presence
of those headers during autoconf and have a simple backup plan rather
than doing all this system detection stuff here (and it might be nice
to reduce the number of build packages from 100000 to 3 or 4). But I
digress.

5) Now it's ready to go. When you compile, of course, don't forget the
appropriate -I and -L paths. Link with -lcurl (gcc links with dlls
just fine).

RUNTIME SETUP:

To actually run your application you'll have to stick the libcurl and
zlib DLLs in your runtime linker path. To do this, copy libcurl.dll
and zlib1.dll to either your Windows system folder, or to the same
directory that your executable is in.

It works great; I've been using it for a couple days now with no
problems. Hope this helps somebody.

Jason
Received on 2007-02-10