This article explains how to compile an experimental version of gcc 4.1 on windows, with the minGW headers, etc.. When you are done, you will have a more or less working copy of gcc 4.1. Please note, though, that it is not production ready. MinGW has not, as of this writing, released a version of gcc 4.0, 4.1, or 4.2. What you are compiling here does not include any of the minGW-specific patches. But you may find this valuable for experimenting with gcc 4.1's new features, trying out its support for std::tr1, etc., and learning how one compiles gcc on a windows-hosted machine.

Please do not request support from the minGW mailing list about problems you have with the resulting executable. (It's fine, however, to ask for help with getting these instructions to work, since these instructions use a working minGW installation.)

This article is adopted (with permission) from an article on Scott Meyers' website, "Building gcc 4 for Windows 2000." You can find that article here. Scott's article, in turn, annotates a posting by Marcelo Slomp to the gcc-help mailing list. You can find Marcelo's original posting here.

I - Setting up the MSYS envirnoment
II - Installing pre-built gcc binaries
III - Creating the gcc host environment
IV - Building and installing gcc


First, we need a fully functional msys environment. You can do this quickly by downloading and installing the msys binaries package, available at

msys 1.0.10: download

For purposes of this How-To, we'll assume you installed msys in the c:\ root. That means that msys is located at: c:\msys


First we download and install a pre-built version of gcc 3. We will later use this to compile gcc 4. Once that's done, the gcc 3 installation can be deleted (as noted below).

Download each of the following binary packages:

from the GNUWin32 project:

from the minGW project:

Having downloaded each of the above files, create a new directory called 'gcc' in the c:\ root. Then extract each file except for libiconv and libintl into this new directory. For libiconv and libintl, only extract the dll's inside the packages' ./bin subdirectory and copy those dll's to the c:\gcc\bin directory.

When extracting (as described below), note that some downloads are .zip files and some are tar.gz files. Be sure your archive extracter puts all the files in the right places. 7-Zip offers an open source win32 tar and zip extractor that makes this easier.

Important: After extraction, go to c:\gcc\bin and delete m4.exe (The reason is that msys uses a different m4 build, included with msys package, and we want to use that one, not the one in c:\gcc\bin that you just downloaded.)

After this, add the c:\gcc\bin directory to the PATH environment variable. To do this, start up msys. In the msys window:

$ PATH=/c/gcc/bin:$PATH

(Note that the "$" is the sh (unix/linux shell) command prompt - you don't type it. You can copy and paste text to the msys prompt.)

Note that gcc's g++ package is not used here - building gcc does not require C++.

To make sure things are working properly, type the following in the msys window:

$ gcc -v

This should show some info about the pre-built gcc you just downloaded. It should mention (among other things) that it is gcc version 3.4.5.


In order to build gcc, we need to first setup a host directory that will contain the new gcc binaries and files. Because this host directory will be used during the build process, the directory must be set up before the build itself.

Assuming you installed msys and the pre-built gcc under c:\, you have now the following directory structure:

 |---gcc                <- here you installed the pre-built gcc (that is, gcc 3.4.5)
 |---msys               <- msys environment is installed here
 |    |---bin
 |    |---doc
 |    |---etc
 |    |---home
 |    |---mingw         <- the new gcc that you will now compile will be installed here.
 |---folder_n (etc.)

Now, you'll create the host environment that will contain the newly compiled gcc (c:\msys\mingw). First, extract mingw-runtime, binutils and win32api files into c:\msys\mingw. (Yes, you already extracted those files into c:\gcc. That was for the host system. Now you are installing them for the target system as well.)

IV - BUILDING AND INSTALLING GCC In msys, create a work directory, where the sources and temporary build files will be placed:

$ cd /
$ mkdir gcc-work && cd gcc-work
$ mkdir {build,source}

Now, download the gcc source packages that you are going to compile. These instructions cover only C and C++, but you can use the same method to compile other gcc language packages.

Copy each of these files to the /gcc-work/source directory. Then in msys, change directories into that directory and extract:

$ cd /gcc-work/source
$ tar jxf gcc-core-4.1.1.tar.bz2
$ tar jxf gcc-g++-4.1.1.tar.bz2

Now, go to the /gcc-work/build directory and create a temporary directory where gcc will be built:

$ cd ../build
$ mkdir gcc
$ cd gcc


(You can read about gcc configuration flags here.)

Type the following at the msys prompt:

$ ../../source/gcc-4.1.1/configure --prefix=/mingw --host=mingw32 \
--target=mingw32 --program-prefix="" --with-as=/mingw/bin/as.exe \
--with-ld=/mingw/bin/ld.exe --with-gcc --with-gnu-ld --with-gnu-as \
--enable-threads --disable-nls --enable-languages=c,c++ \
--disable-win32-registry --disable-shared --without-x --enable-interpreter \
--enable-hash-synchronization --enable-libstdcxx-debug

The above command creates a Makefile that will be used to compile gcc and g++. Now execute make as follows:

$ make CFLAGS="-O2 -fomit-frame-pointer" CXXFLAGS="-mthreads \
-fno-omit-frame-pointer -O2" LDFLAGS="-s -Wl,--stack=0x800000" bootstrap2

The gcc documentation recommends the bootstrap2 option, which should create a more stable, more optimized version of the compiler. The bootstrap2 option results in gcc being compiled, and then that compiled version is used to compile gcc again, and that new version is used to compile gcc once again.

Running the make command will take some time - anywhere from less than half an hour (if you have a relatively fast machine) to several hours (for older, slower hardware).

Now, install your brand new gcc:

$ make install

Your fresh new gcc build is now installed and ready to use. You can now delete the work directory, as well the pre-built gcc directory. Remember, this is not an official minGW release, so use at your own risk!

Important: Don't forget to add to the PATH variable the new gcc's bin directory.

PHP Warning

lib/XmlElement.php:43 Warning[2]: get_class() expects parameter 1 to be object, string given (...repeated 9 times)

lib/XmlElement.php (In template 'navbar' < 'top' < 'body' < 'html'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

lib/XmlElement.php (In template 'navbar' < 'top' < 'body' < 'html'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

lib/XmlElement.php (In template 'browse' < 'body' < 'html'):43 Warning[2]: get_class() expects parameter 1 to be object, string given

Valid XHTML 1.0! Valid CSS!
Page Execution took real: 0.091, user: 0.070, sys: 0.010 seconds , Memory: 2512384

lib/XmlElement.php (In template 'actionbar' < 'browse-footer'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

lib/XmlElement.php (In template 'actionbar' < 'browse-footer'):43 Warning[2]: get_class() expects parameter 1 to be object, string given: