Clone wiki

gdc / MinGWCompile

Building an updated GDC on Windows

The procedures in this document are for setting up D 1.0.

For information on how to build a Linux hosted cross-compiler, read the MinGWCrossCompile page.


The following setup was used to build GDC. I recommend the automatic installers for simplicity and the automatic setup of shortcuts and environment variables. Feel free to do it how you like.


Download the lastest gdc trunk.

hg clone

I like to associate build directories with the version they contain.

mkdir gdc/dev 

Apply patches for windows

For GCC 4.3.X, fixes out of memory bug.


See for more details.

TDM-GCC patches.

  • [buildsys.patch] Minor build system hacks for Cygwin and mSYS
  • [ehstatic.patch] Allow exceptions from DLLs without shared GCC libraries
  • [headerpath.patch] Correctly detect backslashes as path separators in include paths
  • [make-rel-pref.patch] A patch to fix make_relative_prefix() semantics and a little-encountered relocation bug
  • [make-temp-file.patch] A patch to fix make_temp_file() semantics and a little-encountered environment bug

Get the sources for the GCC version nearest the target version.


On Windows it is important to disable antivirus, spyware scanners. Failure to do so will result in extremely long build times.

First you must get GMP and MPFR libraries. I prefer to compile them to be on the safe side.

The easiest way is to simply copy them into the GCC directory as subfolders gmp and mpfr. The downside is that they will be cleaned and recompiled whenever GCC is. A better solution is to compile them separately use --with-{gmp, mpfr} when configuring. If you plan on having GCC build gmp and mpfr then you need to apply the following patches.

Create the output directory.

mkdir /build

Compile GMP and MPFR

Skip this step if you included are letting GCC compile gmp and mpfr.

We need object directories.

mkdir -p dev/build/gmp
mkdir -p dev/build/mpfr

Download the lastest version of GMP: GMP-5.0.1.

Extract to gdc/dev and compile

cd dev/build/gmp

../../gmp-5.0.1/configure --prefix="/build/gmp-5.0.1" --build=mingw32 --enable-fat --enable-static  CFLAGS="-O2 -mtune=generic"

make && make install

cd ../..

Download the lastest version of MPFR: MPFR-3.0.0

Extract to gdc/dev and compile

cd dev/build/mpfr

../../mpfr-3.0.0/configure --prefix="/build/mpfr-3.0.0" --build=mingw32 --with-gmp="/build/gmp-5.0.1" CFLAGS="-O2 -mtune=generic"

make && make install

cd ../..

Compile GDC

In my opinion, the best way to compile GDC for windows is a total replacement for GCC. Some things may break when having multiple versions of GCC coexist.

Get the GCC sources. 4.3.X is what GDC is currently targeted at.

If you just want D, then only get the core tarball. C++ is recommended as well.

Extract gcc to the gdc/dev directory and configure D.

cd gcc-4.3.5

# Only if you have the directory layout described here otherwise copy the d folder from GDC into the gcc folder. On Vista/Win7 you may want to try the mklink command. 
The mklink command can only be done in a windows command prompt(cmd.exe) with adminstrator access.

cd gcc
mklink /D d ..\..\..\d
cd ..

# Version 1 is the default, but it can't hurt to specify it.
./gcc/d/ --d-language-version=1

If everything goes ok setting up GDC then it's time to configure.

warning: if you enable building c++, you may lose the ability to recompile GDC until you reconfigure without it. In other words, once GDC has been successfully built, it cannot be modified and rebuilt without reconfiguring without c++.

cd ../build/gcc

../../gcc-4.3.5/configure --prefix="/mingw" \
    --enable-languages=d \
    --enable-sjlj-exceptions \
    --disable-symvers \
    --disable-werror \
    --disable-win32-registry \
    --disable-nls \
    --enable-threads \
    --enable-version-specific-runtime-libs \
    --with-gmp=/build/gmp-5.0.1 --with-mpfr=/build/mpfr-3.0.0 \
    --with-pkgversion="GDC 138:d53a8be7c0ed  DMD 1.055"\
    --with-bugurl="" \

With GCC 4.5 and possibly 4.6 LPATH should be used to direct GCC to the compiler's lib directory.

LPATH=/mingw/lib make STAGE1_CFLAGS="-g3 -O0" 2>&1 | tee build.log

make DESTDIR="/build/Mingw32" install

Used GCC options:

  • --prefix : Where GDC installs to, due to a bug, this is also the path GDC will search for all default directories.
  • --enable-languages : Which languages to enable.
  • --enable-sjlj-exceptions :
  • --with-bugurl : Who to send bugs to.
  • --with-pkgversion : Version string, I like to include GDC revision and DMD version.
  • --disable-symvers :
  • --disable-werror :
  • --disable-win32-registry :
  • --disable-nls :
  • --enable-threads :
  • --enable-version-specific-runtime-libs :
  • --with-gmp : Tells GCC where GMP is.
  • --with-mpfr : Tells GCC where MPFR is.
  • --disable-bootstrap : By default GCC will build the compiler 3 times. This limits it to once.

Finishing the build environment

Additional files will be needed to complete the GDC install. Everything should be extracted to the root directory of GDC.

Copied from

All files can be found at

  • binutils 2.20.51
  • mingw-runtime 3.18
  • w32api 3.14


  • mingw-utils : mingw-utils-0.4-1-mingw32-bin.tar.lzma
  • mingw32-make : make-3.81-20090914-mingw32-bin.tar.gz
  • gdb. has one, but I think there was a newer 6.8 out there. It may be possible to take the lastest sources and compile them with the patches from the previous url.

Common Issues

Linker cannot find crtX.o or dllcrtX.o

MinGW is considered a cross build so GCC will not look in the compiler's directory for system libraries. This can be fixed by using LPATH for the make command.