Like wget, curl also helps you retrieve files from the Internet. curl seems to be quite powerful and popular. This post shows how to make a static build of curl, which doesn't need particular DLL's.
If you haven't set up MinGW yet, read one of the following guides to install MinGW.
- Installing MinGW on Windows
- Installing MinGW-w64 on Windows
- Setting up MinGW64 with Cygwin
If you have installed MinGW64, don't forget to append --build=i686-w64-mingw32 to theconfigurelines shown in the examples below. - TDM-GCC MinGW-w64 Installation
- Setting Up Cygwin For C/C++ Software Development on Windows
Then, compile zlib, as shown in this post.
make -f win32/Makefile.gcc cp -iv zconf.h zlib.h /mingw/include cp -iv libz.a /mingw/lib
Next, build OpenSSL.
./Configure -DHAVE_STRUCT_TIMESPEC -L/mingw/lib -lz -lws2_32 --prefix=/mingw zlib mingw make make install
Then, compile libssh2.
./configure --prefix=/mingw --with-libz --with-openssl --disable-examples-build make make install
Optionally, compile librtmp.
make SYS=mingw INC=-I/mingw/include LDFLAGS=-L/mingw/lib cd librtmp mkdir /mingw/include/librtmp cp -iv amf.h http.h log.h rtmp.h /mingw/include/librtmp cp -iv librtmp*.a /mingw/lib
Create /mingw/lib/pkgconfig/librtmp.pc.
prefix=/mingw exec_prefix=${prefix} libdir=${exec_prefix}/lib incdir=${prefix}/include/librtmp Name: librtmp Description: RTMP implementation Version: 2.3 Requires: openssl libcrypto URL: http://rtmpdump.mplayerhq.hu Libs: -L${libdir} -lrtmp -lz Libs.private: -lws2_32 -lwinmm -lgdi32 -lssl -lcrypto Cflags: -I${incdir}If you're going to link curl with libmetalink, compile expat.
./configure --prefix=/mingw --disable-shared --enable-static make make install
Then, build libmetalink.
./configure --prefix=/mingw --disable-shared make make install
I downloaded the curl source from curl.haxx.se and configured curl as follows:
./configure --prefix=/mingw --enable-ipv6 --disable-shared --with-librtmp --with-libmetalink LIBS='-lwldap32'
This enabled most of the curl features except a few obscure functions.
Sometimes, curl configure script can't detect some libraries. I had to modify the LIBS variable.
./configure --build=i686-w64-mingw32 --prefix=/mingw --enable-ipv6 --disable-shared --with-librtmp --with-libmetalink LIBS='-lwldap32 -lssl -lcrypto -lz -lws2_32 -lwinmm -lgdi32 -liconv'
Then, I compiled curl with the following command.
make
I enabled the metalink feature of curl and got errors compiling tool_metalink.c. To work around this issue, I just forced it to use CRYPT32.DLL instead of OpenSSL (my patch).
make install
The command above will copy the following files into /mingw.
bin/curl.exe bin/curl-config include/curl/curl.h include/curl/curlbuild.h include/curl/curlrules.h include/curl/curlver.h include/curl/easy.h include/curl/mprintf.h include/curl/multi.h include/curl/stdcheaders.h include/curl/typecheck-gcc.h include/curl/types.h lib/libcurl.a lib/libcurl.la lib/pkgconfig/libcurl.pc share/man/man1/curl-config.1 share/man/man1/curl.1 share/man/man3/curl_easy_cleanup.3 share/man/man3/curl_easy_duphandle.3 share/man/man3/curl_easy_escape.3 share/man/man3/curl_easy_getinfo.3 share/man/man3/curl_easy_init.3 share/man/man3/curl_easy_pause.3 share/man/man3/curl_easy_perform.3 share/man/man3/curl_easy_recv.3 share/man/man3/curl_easy_reset.3 share/man/man3/curl_easy_send.3 share/man/man3/curl_easy_setopt.3 share/man/man3/curl_easy_strerror.3 share/man/man3/curl_easy_unescape.3 share/man/man3/curl_escape.3 share/man/man3/curl_formadd.3 share/man/man3/curl_formfree.3 share/man/man3/curl_formget.3 share/man/man3/curl_free.3 share/man/man3/curl_getdate.3 share/man/man3/curl_getenv.3 share/man/man3/curl_global_cleanup.3 share/man/man3/curl_global_init.3 share/man/man3/curl_global_init_mem.3 share/man/man3/curl_mprintf.3 share/man/man3/curl_multi_add_handle.3 share/man/man3/curl_multi_assign.3 share/man/man3/curl_multi_cleanup.3 share/man/man3/curl_multi_fdset.3 share/man/man3/curl_multi_info_read.3 share/man/man3/curl_multi_init.3 share/man/man3/curl_multi_perform.3 share/man/man3/curl_multi_remove_handle.3 share/man/man3/curl_multi_setopt.3 share/man/man3/curl_multi_socket.3 share/man/man3/curl_multi_socket_action.3 share/man/man3/curl_multi_strerror.3 share/man/man3/curl_multi_timeout.3 share/man/man3/curl_share_cleanup.3 share/man/man3/curl_share_init.3 share/man/man3/curl_share_setopt.3 share/man/man3/curl_share_strerror.3 share/man/man3/curl_slist_append.3 share/man/man3/curl_slist_free_all.3 share/man/man3/curl_strequal.3 share/man/man3/curl_unescape.3 share/man/man3/curl_version.3 share/man/man3/curl_version_info.3 share/man/man3/libcurl-easy.3 share/man/man3/libcurl-errors.3 share/man/man3/libcurl-multi.3 share/man/man3/libcurl-share.3 share/man/man3/libcurl-tutorial.3 share/man/man3/libcurl.3
To Create a Shared Library libcurl-4.dll from Static libcurl.a
As usual, there's some confusion regarding how to name dynamic libraries of open-source software. I found some instances of libcurl-4.dll and some instances of libcurl.dll. It doesn't really matter because we can use gcc to create a shared library with any name from the static library. I ran the following command to create libcurl-4.dll. This file may not be desirable because it contains all the dependencies inside.
cd /mingw/lib gcc -shared -o libcurl-4.dll -Wl,--out-implib,libcurl-4.dll.a -Wl,--whole-archive libcurl.a libssh2.a libssl.a libcrypto.a librtmp.a libidn.a libiconv.a libz.a -Wl,--no-whole-archive -L/mingw/lib -lwinmm -lgdi32 -lcrypt32 -lws2_32 -lwldap32
We get the shared library libcurl-4.dll and the import library libcurl-4.dll.a.
To Test Curl
After successfully building curl, I tested my win32 build by fetching Linux ISO's with curl. You can get my build from the Download page.
/mingw/bin/curl.exe -O ftp://ftp.pardus.org.tr/pub/ISO/Kurulan/2011.2/Pardus-2011.2-Cervus-elaphus-i686.iso
Without the -O option, curl will throw a handful of garbage onto the terminal screen and panic. I also tested my curl build for the metalink protocol.
/mingw/bin/curl.exe --metalink -O file://openSUSE-12.2-DVD-i586.iso.meta4



