Compiling GCC 4.6 Nightlies on Windows with MinGW and MSYS

Step 1:

Download these packages

You can find more up-to-date versions here:

The above packages will get you some of the dependencies of compiling gcc on windows plus a whole bunch of other things that aren’t needed, but I found it easier to use the stuff there.

Also, you should download the latest gcc-core and gcc-g++ packages from the LATEST-4.6 folder on one of the GCC mirrors, I use, Extract them so that the tars are in the sources folder with the rest of the packages.

2. Create a directory

3. Extract sources and msys to anywhere.

4. Download the latest flex and extract it to where you extracted msys so that flex.exe is in msys/bin.

5. Do the same for Bison

6. Copy this script and save it in the sources folder from earlier as


# Ensure that mingw-runtime and w32api exist.
test -d /c/temp/gcc/mingw-runtime || { echo /c/temp/gcc/mingw-runtime does not exist. ; exit; }
test -d /c/temp/gcc/w32api || { echo /c/temp/gcc/w32api does not exist. ; exit; }

# Extract vanilla sources.

tar -C /c/temp/gcc -xf $2

tar -C /c/temp/gcc -xf $3
tar -C /c/temp/gcc -xf gmp-5.0.1.tar
tar -C /c/temp/gcc -xf mpfr-3.0.0.tar
patch -Z -d /c/temp/gcc/mpfr-3.0.0 -p1 < mpfr-3.0.0.patch
tar -C /c/temp/gcc -xf mpc-0.8.2.tar

# Arrange vanilla sources.
cd /c/temp/gcc
mv $1 src
mv gmp-5.0.1 src/gmp
mv mpfr-3.0.0 src/mpfr
mv mpc-0.8.2 src/mpc

# Copy mingw-runtime and w32api.
mkdir -p /include
rm -rf /mingw
mkdir /mingw
cp -r mingw-runtime/* /mingw
cp -r w32api/* /mingw

# Configure.
mkdir build dest
cd build
../src/configure –prefix=/c/temp/gcc/dest –enable-languages=c,c++ –with-arch=i686 –with-tune=generic –disable-libstdcxx-pch –disable-nls –disable-shared –disable-sjlj-exceptions –disable-win32-registry –enable-checking=release

# –disable-libstdcxx-pch : I don’t use this, and it takes up a ton of space.
# –disable-nls : I don’t want Native Language Support.
# –disable-shared : I don’t want DLLs.
# –disable-sjlj-exceptions : I don’t want SJLJ, I want DW2.
# –disable-win32-registry : I don’t want this abomination.
# –enable-checking=release : I don’t want expensive checking if this came from SVN or a snapshot.
# –enable-lto : LTO is not enabled by default for MinGW, but can be explicitly requested.

# Build and install.
make bootstrap install “CFLAGS=-g0 -Os -fomit-frame-pointer” “CXXFLAGS=-g0 -O3 -fomit-frame-pointer -mthreads” “CFLAGS_FOR_TARGET=-g0 -Os -fomit-frame-pointer” “CXXFLAGS_FOR_TARGET=-g0 -O3 -fomit-frame-pointer -mthreads” “BOOT_CFLAGS=-g0 -Os -fomit-frame-pointer” “BOOT_CXXFLAGS=-g0 -O3 -fomit-frame-pointer -mthreads” || { echo EPIC FAIL ; exit; }

The above script is a modified version of what came from

7. Launch your msys shell from the msys directory you created earlier and navigate to your sources-6.6 directory and execute the following scripts:

8. Now run the script like this (assuming you have the same nightly as I do)

./ gcc-4.6-20101016 gcc-core-4.6-20101016.tar "gcc-g++-4.6-20101016.tar"

The 1st parameter is the nightly build version, the 2nd parameter is the name of the gcc core archive. the 3rd is the name of the g++ archive.

9. This should fail with a message like this:

make[3]: Circular s-tm-texi tmp-tm.texi
/bin/sh ../../src/gcc/../move-if-change tmp-tm.texi tm.texi

Verify that you have permission to grant a GFDL license for all
new text in tm.texi, then copy it to ../../src/gcc/doc/tm.texi.
make[3]: *** [s-tm-texi] Error 1
make[3]: Leaving directory `/c/temp/gcc/build/gcc'

10. Now you need to navigate to
and copy

11. Now you need to navigate to

And modify the following file:
Modify line 44 to wrap it in a #ifndef like this:

#ifndef WIN32

Then navigate to what will now be line 461 and do the same thing:

#ifndef WIN32
check (WIFEXITED (status) && WEXITSTATUS (status) == 0, LDPL_FATAL,
"lto-wrapper failed");

Now save the file and move on to the next step.

12. Now run the 2nd script (I saved it in the sources-6.6 folder as

# Arrange vanilla sources.
cd /c/temp/gcc

cd build
# Build and install.
make bootstrap install "CFLAGS=-g0 -Os -fomit-frame-pointer" "CXXFLAGS=-g0 -O3 -fomit-frame-pointer -mthreads" "CFLAGS_FOR_TARGET=-g0 -Os -fomit-frame-pointer" "CXXFLAGS_FOR_TARGET=-g0 -O3 -fomit-frame-pointer -mthreads" "BOOT_CFLAGS=-g0 -Os -fomit-frame-pointer" "BOOT_CXXFLAGS=-g0 -O3 -fomit-frame-pointer -mthreads" || { echo EPIC FAIL ; exit; }

# Cleanup.
rm -rf /mingw
cd /c/temp/gcc/dest
rm -rf share
cd bin
rm c++.exe gccbug i686-pc-mingw32-*
cp gcc.exe cc.exe
cd ..
find -name "*.exe" -type f -print -exec strip -s {} ";"

13. Now everything should work!

~ by ra1ndog on October 22, 2010.

One Response to “Compiling GCC 4.6 Nightlies on Windows with MinGW and MSYS”

  1. Thanks ra1ndog! You are the man! I will be compiling gcc 4.6 this weekend. Thanks again for putting these instructions together.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.