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.

Having downloaded each of the above files, create a new directory called 'gcc' in the c:\ root. Then extract each file exceptforlibiconvandlibintl 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.

III - CREATING THE GCC HOST ENVIRONMENT

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:

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.

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.