Building GCC on Windows
Instructions for a native bootstrap of GCC on Windows for i386-pc-mingw32.
These instructions will be merged into the GCC documentation when they become more mature.
You must have the MinGW toolchain installed to build GCC. The toolchain is composed of two parts, the host libraries and tools, and the host compiler. A complete toolchain which satisfies the requirements below can be installed using the installer from http://www.mingw.org.
These notes only discuss MinGW-specific prerequisite issues. Please see http://gcc.gnu.org/install/prerequisites.html for a complete list of prerequisites.
mingw-runtime (version 3.12 or higher): This is the equivalent of libc on Unix which provides an interface to Microsoft's C runtime that is shipped with Windows.
Host Tools and Libraries
w32api: This is a free implementation of the Windows API, equivalent to the Windows SDK, which provides the system-level interface needed by mingw-runtime and some parts of GCC. It is possible, with some modifications, to use Microsoft’s Platform SDK instead.
binutils (version 2.15 or higher): The GCC build needs an assembler and linker.
gcc: You must have GCC 2.95 or better installed. At this time, building with other Windows compilers probably will not work.
Tools: A set of Unix-like tools must be present to build GCC. There are at least three different ways to get the set of required tools.
MSYS: MSYS is an environment available at <http://www.mingw.org> that is designed to work with MinGW, and it should work seamlessly. MSYS is a stripped-down and specialized fork of Cygwin. Unfortunately, in the past, MSYS has suffered from various bugs that have made building GCC difficult.
Cygwin: The Cygwin environment available at http://www.cygwin.com can provide the host tools. An advantage of using Cygwin is that it comes with almost all of the tools needed for developing and testing GCC. If Cygwin is used, two modifications must be made:
- ln that does not create Cygwin-style symbolic links must be placed in the path before Cygwin. The ln from MSYS should work here. This script can be used:
##!/bin/sh exec cp -p `echo $* | sed -r 's/(^| )-[^ ]*//g'`
- uname must be modified to report MINGW32_NT-5.1 instead of CYGWIN_NT-5.1 so config.guess guesses correctly. The easiest way is to just use the uname from MSYS. Alternately, you can pass --build=i386-pc-mingw32 to configure to override config.guess.
autogen: This is not included in Cygwin, MSYS, or UnxUtils. Presently, there is a problem with building autogen on Cygwin. For a workaround, see the autogen-users mailing list: http://sourceforge.net/mailarchive/message.php?msg_name=1ca1c1410805011500u33bfd13fk2eedcb98fd53435e%40mail.gmail.com.
mingw32-make: In some cases, the mingw32-make build provided on http://www.mingw.org may work better.
phreads-win32: This is needed presently to make libgomp compile. However, OpenMP does not actually seem to work at present on MinGW.
See http://gcc.gnu.org/install/prerequisites.html for a complete list of optional prerequisites.
All prerequisite tools should be in the PATH environment variable.
The console emulation in Cygwin and MSYS has a known problem that causes it to lose some output information from GCC, which can cause build failures to be rather mysterious. RXVT, for example, has this problem. For this reason, the Microsoft console should be used. Alternately, a console emulator that does not have this problem can be used, such as Console 2 from http://sourceforge.net/projects/console/.
Sometimes CRLF issues are a problem. Cygwin bash has a feature that can mitigate some of these problems, which can be activated in the following way: set -o igncr export SHELLOPTS
Including \r in the IFS environment variable may also be helpful in avoiding these problems.
Please see the GCC installation instructions for complete details.
GCC must be configured using a relative path.
Building MinGW is typically quite slow, apparently due to slow Makefile and shell script execution. Using multiple processors with make -jN can substantially speed up the process.
To enable all languages and all directories (except mudflap), a command similar to the following example can be used. Note that you will need to specify your own paths to configure, libiconv, gmp, and mpfr.
../gccsrc/configure --enable-languages=c,ada,c++,fortran,java,objc,obj-c++ --disable-sjlj-exceptions --enable-libgcj --enable-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-concept-checks --enable-version-specific-runtime-libs --prefix=/mingw --with-gmp=/mingw/src/gcc/gmp-mpfr-root --with-mpfr=/mingw/src/gcc/gmp-mpfr-root --with-libiconv-prefix=/mingw/src/gcc/libiconv-root
The DESTDIR variable can be used to control the output path.
make DESTDIR=/mingw/src/mytest/root install