Monday, June 15, 2009

My Adventure with MinGW in Linux

I tried to cross-compile GTK+ to Windows in Linux, but I didn't succeed. When I tried to cross-compile Freetype in Linux, make tried to run a Windows executable and failed. I will probably try again with Wine installed. Anyway, I was able to compile GTK+ in Windows. Here I show how I compiled some libraries with MinGW cross-compiler in Linux, in case I try again later.




  1. First, I installed mingw32-runtime, mingw32-binutils and mingw packages. Then, I created a directory which will contain compiled binaries:


    mkdir -p /opt/mingw/lib

    zcat /usr/share/doc/mingw32-runtime/mingwm10.dll.gz > /opt/mingw/lib/mingwm10.dll


  2. Compiling Zlib


    Since zlib is depended upon by most libraries, I downloaded zlib from here and compiled it first:


    cd $HOME

    tar xzvf /tmp/zlib-1.2.3.tar.gz

    cd zlib-1.2.3

    CC=/usr/bin/i586-mingw32msvc-gcc AR="/usr/bin/i586-mingw32msvc-ar rc" RANLIB=/usr/bin/i586-mingw32msvc-ranlib ./configure --prefix=/opt/mingw

    make

    make install

    To make sure the compiled library works, I renamed the sample executables example and minigzip to example.exe and minigzip.exe respectively and copied them to a Windows machine. Then, I ran them for test. The sample programs worked as I typed the following commands:


    example.exe

    minigzip.exe -d foo.gz

    minigzip.exe foo


  3. Porting Iconv to Windows


    I downloaded libiconv from here and cross-compiled it as follows:


    cd $HOME

    tar xvzf libiconv-1.11.1.tar.gz

    cd libiconv-1.11.1

    PATH=/usr/i586-mingw32msvc/bin:$PATH CC=/usr/bin/i586-mingw32msvc-gcc RC=/usr/bin/i586-mingw32msvc-windres WINDRES=/usr/bin/i586-mingw32msvc-windres ./configure --host=i586-pc-mingw32 --prefix=/opt/mingw --enable-relocatable CPPFLAGS="-Wall -I/usr/i586-mingw32msvc/include -I/opt/mingw/include" CFLAGS="-O2 -g" LDFLAGS="-L/usr/i586-mingw32msvc/lib -L/opt/mingw/lib"

    PATH=/usr/i586-mingw32msvc/bin:$PATH make

    PATH=/usr/i586-mingw32msvc/bin:$PATH make install

    There's an executable file iconv created in /opt/mingw/bin/. I renamed it as iconv.exe and copied it together with libcharset-1.dll and libiconv-2.dll to Windows for test.


    iconv.exe --list


  4. Porting Gettext to Windows


    GNU gettext is a localization tool for Linux. I cross-compiled it for Windows as follows:


    PATH=/usr/i586-mingw32msvc/bin:$PATH CC=/usr/bin/i586-mingw32msvc-gcc CXX=/usr/bin/i586-mingw32msvc-g++ WINDRES="/usr/bin/i586-mingw32msvc-windres" ./configure --host=i586-pc-mingw32 --prefix=/opt/mingw --disable-java --disable-native-java --enable-threads=win32 --enable-relocatable --without-emacs CPPFLAGS="-Wall -I/usr/i586-mingw32msvc/include -I/opt/mingw/include" CFLAGS="-O2 -g" CXXFLAGS="-O2 -g" LDFLAGS="-L/usr/i586-mingw32msvc/lib -L/opt/mingw/lib"

    PATH=/usr/i586-mingw32msvc/bin:$PATH make

    PATH=/usr/i586-mingw32msvc/bin:$PATH make install

    To test gettext for Windows, copy libintl-8.dll, libgettextsrc-0-17.dll, libgettextlib-0-17.dll and msgfmt.exe to Windows. Also, libiconv-2.dll from above is required by libintl-8.dll. Get a message file in *.po format from somewhere and run msgfmt as follows:


    msgfmt.exe -o fr.mo fr.po

    A binary message file fr.mo will be generated from fr.po in the example above.



  5. Cross-compiling Expat library for Windows


    The eXpat library is required by fontconfig. I downloaded eXpat from http://expat.sourceforge.net/ and compiled it as follows:


    PATH=/usr/i586-mingw32msvc/bin:$PATH CC=/usr/bin/i586-mingw32msvc-gcc CPP=/usr/bin/i586-mingw32msvc-cpp ./configure --host=i586-mingw32msvc --prefix=/opt/mingw CPPFLAGS="-Wall -I/usr/i586-mingw32msvc/include -I/opt/mingw/include" LDFLAGS="-L/usr/i586-mingw32msvc/lib -L/opt/mingw/lib" CFLAGS="-O2 -g"

    make

    make install

    To test the Expat library, I copied libexpat-1.dll and xmlwf.exe to Windows and ran the following command:


    xmlwf.exe -v


  6. Porting Libxml2 to Windows


    I downloaded libxml2 from ftp://xmlsoft.org/libxml2/ and cross-compiled it as follows:


    PATH=/usr/i586-mingw32msvc/bin:$PATH CPP=/usr/bin/i586-mingw32msvc-cpp CC=/usr/bin/i586-mingw32msvc-gcc ./configure --prefix=/opt/mingw --host=i586-mingw32msvc --without-debug --without-legacy --with-minimum --without-python --without-sax1 --without-modules CPPFLAGS="-Wall -I/usr/i586-mingw32msvc/include -I/opt/mingw/include" CFLAGS="-O2 -g" LDFLAGS="-L/usr/i586-mingw32msvc/lib -L/opt/mingw/lib"

    PATH=/usr/i586-mingw32msvc/bin:$PATH make

    PATH=/usr/i586-mingw32msvc/bin:$PATH make install

    To test libxml2 for Windows, I copied libxml2-2.dll and xmllint.exe to Windows and ran the following command:


    xmllint.exe --version


  7. Porting Glib2 to Windows


    I downloaded Glib2 from here and cross-compiled it as follows:


    PATH=/usr/i586-mingw32msvc/bin:$PATH ./configure --host=i586-mingw32msvc --enable-debug=no --disable-selinux --disable-xattr --with-threads=win32 --with-pcre=internal --disable-fam --disable-gtk-doc --prefix=/opt/mingw CC=/usr/bin/i586-mingw32msvc-gcc CPP=/usr/bin/i586-mingw32msvc-cpp CPPFLAGS="-Wall -I/usr/i586-mingw32msvc/include -I/opt/mingw/include" LDFLAGS="-L/usr/i586-mingw32msvc/lib -L/opt/mingw/lib" CFLAGS="-O2 -g"

    PATH=/usr/i586-mingw32msvc/bin:$PATH make

    PATH=/usr/i586-mingw32msvc/bin:$PATH make install

    To test my Glib2 build, I copied libglib-2.0-0.dll, libintl-8.dll and libiconv-2.dll to Windows and overwrote libglib-2.0-0.dll supplied by Pidgin. I started Pidgin and it launched successfully.



1 comment:

  1. I'm following some of your posts trying to compile mdbtools for windows with mingw... thanks a lot!

    ReplyDelete

About This Blog

KBlog logo This blog seeks to provide a collection of interesting pictures found on the Web. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

Powered By Blogger