June 10, 2011

Cross compile wget on Linux for Windows

GNU wget does not release binary on Windows, and it is not very straight-forward to compile for Windows, but it works great on Windows. I just compiled wget 1.12 for Windows. Please DOWNLOAD IT HERE

I did this on Debian 5.0, and I have the following mingw package installed (not https supported, shouldn't be hard to add if you want to compile the openssl):

dpkg -l | grep -i mingw
ii  mingw32                   4.2.1.dfsg-1                       Minimalist GNU win32 (cross) compiler
ii  mingw32-binutils          2.18.50-20080109-1                 Minimalist GNU win32 (cross) binutils
ii  mingw32-runtime           3.13-1                             Minimalist GNU win32 (cross) runtime

This is how to compile wget for Windows on a Linux host using the MingW32 for Linux tool chain

1. download the gnu wget source at http://www.gnu.org/software/wget/
2. tar zxvf wget-1.12.tgz;  cd wget-1.12; 
3. ./configure CC=i586-mingw32msvc-gcc AR=i586-mingw32msvc-ar RANLIB=i586-mingw32msvc-ranlib --disable-ipv6 --host=mingw32
4. change "src/config.h" to add 
           #define WINDOWS 1
           #define INHIBIT_WRAP 1
   and comment out these two lines:
           //#define HAVE_SYMLINK 1
           //#define HAVE_USLEEP 1
4.1 comment out "src/host.c" line 67
           //extern int h_errno;
5. vi src/Makefile, add "mswindows.o" to the end of the "am_wget_OBJECTS" assignment
6. search for "LIBS =", and append "-l ws2_32 -s"
7. Make

The wget.exe file is located in src/wget.exe

Enjoy!

5 comments:

  1. Hi, please share compiled file
    tnx

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. I'm using Ubuntu 10.04, mingw32 Version: 4.2.1.dfsg-1ubuntu2, mingw32-binutils Version: 2.20-0.1, mingw32-runtime Version: 3.15.2-0ubuntu1.
    Not working.

    i586-mingw32msvc-gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC=\"/usr/local/etc/wgetrc\" -DLOCALEDIR=\"/usr/local/share/locale\" -I. -I../lib -I ../md5 -O2 -Wall -MT host.o -MD -MP -MF .deps/host.Tpo -c -o host.o host.c
    host.c:67: error: conflicting types for 'WSAGetLastError'
    /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/include/winsock.h:461: error: previous declaration of 'WSAGetLastError' was here
    host.c: In function 'host_errstr':
    host.c:358: warning: return discards qualifiers from pointer target type
    host.c:362: warning: return discards qualifiers from pointer target type
    host.c:364: warning: return discards qualifiers from pointer target type
    make[2]: *** [host.o] Error 1
    make[2]: Leaving directory `/downloads/wget-1.12/src'

    ReplyDelete
  4. Anonymous, see the updated link for download the binary wget-1.12.exe

    ReplyDelete
  5. seconddima, see updated instructions on bullet point 4 and 4.1 on how to compile on Ubuntu 10.4

    ReplyDelete