Compdigitec Labs

« | Home | »

Compiling mingw-w64 with GCC 4.8

By admin | February 7, 2013

You need at least mingw-w64 rev 5579, build-essential, and a working compiler. Be sure to have installed flex and bison.

Replace the demo prefix /usr/i686-w64-mingw32 with whatever you feel like, if you want to.

Extract the gcc tarball, and pull in mpfr, mpc, and and gmp tarballs under the extracted gcc root.

sudo mkdir /usr/i686-w64-mingw32

../binutils-2.22/configure --disable-multilib --target=i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32
make -j4
sudo make install

ln -s /usr/i686-w64-mingw32/i686-w64-mingw32 /usr/i686-w64-mingw32/mingw

../mingw-w64/mingw-w64-headers/configure --build=i686-linux-gnu --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/i686-w64-mingw32 # notice the extra i686-w64-mingw32
make
sudo make install

../gcc-4.8-20130120/configure --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++  --with-system-zlib --enable-shared --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make all-gcc -j4
sudo make install-gcc

../mingw-w64/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32 --with-sysroot=/usr/i686-w64-mingw32
make -j4
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

cd ../gcc-4.8-20130120-build
make -j4
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find dllcrt2.o: No such file or directory
sudo ln -s /usr/i686-w64-mingw32/lib/dllcrt2.o /usr/i686-w64-mingw32/mingw/lib/
make
# checking for ld that supports -Wl,--gc-sections... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
# dig into i686-w64-mingw32/libstdc++-v3/config.log, you find this:
# /usr/i686-w64-mingw32/i686-w64-mingw32/bin/ld: cannot find crt2.o: No such file or directory
# solution:
sudo ln -s /usr/i686-w64-mingw32/lib/crt2.o /usr/i686-w64-mingw32/mingw/lib/
make
sudo make install

../../../mingw-w64/mingw-w64-libraries/winstorecompat/configure --prefix=/usr/i686-w64-mingw32 --host=i686-w64-mingw32
make
sudo su
export PATH=/usr/i686-w64-mingw32/bin:$PATH
make install
exit

And just for fun, let’s test it:

i686-w64-mingw32-gcc --version
# i686-w64-mingw32-gcc (GCC) 4.8.0 20130120 (experimental)
# Copyright (C) 2013 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions.  There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

i686-w64-mingw32-gcc ~/c/hello.c

file a.exe
# a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

wine a.exe
# Hello, World!

Bibliography:

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Linux | No Comments »

Comments