Wednesday, November 7, 2007

Quickstart: libcurl and mingw (plain http)

The win32 builds of libcurl available on the Curl download page have way too many library dependencies (openldap/zlib/openssl etc). That makes sense since curl supports fetching resources using any of those those protocols. However, if all you want to do is just use curl for http use in your program, its simply better to compile the libcurl source to get the tiny libcurl library you need.

The below assumes that you have downloaded and installed mingw and you have mingw32-make in your PATH.

  • Grab the libcurl source from the download page. I took

  • Extract to a directory (preferably without spaces). We'll call this LIBCURL_HOME

  • Open LIBCURL_HOME/lib/setup.h. Add a "#define HTTP_ONLY" (minus quotes ofcourse) just before the first line in the file. This disables all protocols except http. Read LIBCURL_HOME/docs/INSTALL for further information.

  • Open a command shell, change to this directory and use command "mingw32-make mingw32". (Read LIBCURL_HOME/docs/INSTALL for more info on this)

  • After compilation is finished, you should have 'libcurldll.a' and 'libcurl.a' present in LIBCURL_HOME/lib

  • Change directory to LIBCURL_HOME/docs/examples. We'll now attempt to compile and run the simples libcurl example program 'simple.c'

  • Run "gcc -DCURL_STATICLIB -I ..\..\include simple.c ..\..\lib\libcurl.a -lws2_32 -lwinmm -o simple" at the command line. Alternatively you can run
    "gcc -DCURL_STATICLIB -I ..\..\include simple.c -L..\..\lib -lcurl -lws2_32 -lwinmm -o simple.exe".(See Curl FAQ)

  • A file 'simple.exe' should be produced. Running this dumps the home page of curl to stdout as shown below

  • ws2_32 is the winsock library (you can also do -lwsock32), winmm is a library for windows multimedia - as far as I can see there is only one time function used from this library


RLee said...

Thanks! This was very helpful in getting a minimalist version of the libs up and running quickly. Your instructions were right on and I had no errors or issues. :-)

Newry said...

oh well,u were better looking in my memory!! anyways hi...i don't know if u remember me, just wanted to say hi!
Dr. Newry Chandra

Tarun Ramakrishna Elankath said...

Hi Newry,

I suppose I have just got older and uglier. :). And of-course I remember you. How is it going Doc?

Oooh-la-la.. DOCTOR Newry Chandra has a nice ring to it.

Mailed you at your gmail/yahoo address.


calin said...

Hi Tarun
I followed all steps but i have problems on last one.
i can't see it code HTML when execute simple.exe like you showed it on last screen.
any suggest?


Anonymous said...


Most likely the URL encoded in simple.c is "". Just edit the file and change it to something like: "".