Clone wiki

gdc / GDC on Android

Note: This tutorial should give you a usable GDC for Android. GDC on Android is not supported in any way, and especially druntime and phobos may need some updates to be usable.


Differences to normal GDC

  • version(Android) is defined
  • doesn't link -lpthread and -lrt by default (not available on android)
  • Note: Android/bionic does not claim to be posix compliant, so there's some work needed to make druntime & phobos work

Building a toolchain with gdc for the Android NDK

Linux host

The official Android NDK r7 uses an old GCC version (4.4.3) which isn't supported by GDC. We'll build a new toolchain based on GCC 4.6.2

Needed Packages

This tutorial was tested on Debian Testing. You'll need at least the following packages:

build-essential libncurses5-dev texinfo

Getting the sources

First we'll need a directory in which we'll put all our files. Just choose any directory and replace all instances of $BASE_DIR in the tutorial with your directory.


Now let's download and patch the sources:

mkdir toolchain-src
cd toolchain-src

git clone

mkdir gmp && cd gmp
cd ../

mkdir gdb && cd gdb
tar xjf gdb-7.4.tar.bz2
cd ../

mkdir mpc && cd mpc
cd ../

mkdir mpfr && cd mpfr
cd ../

mkdir binutils
cd binutils/
tar xjf binutils-2.22.51.tar.bz2
cd ../

wget -O gcc-android.patch
mkdir gcc
cd gcc/
tar xjf gcc-4.6.2.tar.bz2
cd gcc-4.6.2
patch -p1 -i ../../gcc-android.patch
cd ../../

We'll now patch GCC to add support for D. Note: Skip this code snippet to simply build a GCC 4.6.2 toolchain without D. It's recommended to get a toolchain without D working first.

hg clone
cd gdc
hg update android
cd ../

cd gcc/gcc-4.6.2/
ln -s ../../../gdc/d gcc/d
cd ../../

wget -O build-d.patch
cd build
patch -p1 -i ../build-d.patch
cd ../

Getting the android NDK

Now you'll have to download the official Android NDK r7 and extract it to BASE_DIR

tar xjf android-ndk-r7-linux-x86.tar.bz2

We'll have to apply a small patch as well:

wget -O build-mpc.patch
cd android-ndk-r7
patch -p1 -i ../build-mpc.patch
cd ../

Note: Your BASE_DIR directory should now look like this:


Build the toolchain

cd android-ndk-r7/build/tools/
NUM_JOBS=1 DFLAGS="-fno-section-anchors" ./ --gmp-version=5.0.3 --mpfr-version=3.0.1 --mpc-version=0.9 --binutils-version=2.22.51 --gdb-version=7.4 $BASE_DIR/toolchain-src $BASE_DIR/android-ndk-r7 arm-linux-androideabi-4.6.2

Once the build is finished, your toolchain is in BASE_DIR/android-ndk-r7/toolchains/arm-linux-androideabi-4.6.2/prebuilt/linux-x86

Windows host

We'll compile the windows toolchain on a linux host. Debian Testing was used to test this tutorial.

Follow the linux build instructions

Follow the linux instructions till the "Build the toolchain" section.

Additional packages

We'll need the following additional packages for the windows build:

gcc-mingw32 mingw32-binutils mingw32-runtime

Additional patches

We'll also need one additional patch:

cd $BASE_DIR/toolchain-src
wget -O build-mingw.patch
cd build
patch -p3 -i ../build-mingw.patch
cd ../

Depending on your build system, you'll have to apply another patch: if you have a i386-linux-gnu-gcc executable, you must not apply this patch. But if your gcc is called i486-linux-gnu-gcc you must apply it.

wget -O build-i486-host.patch
cd android-ndk-r7
patch -p2 -i ../build-i486-host.patch
cd ../

Build the toolchain

cd android-ndk-r7/build/tools/
NUM_JOBS=1 DFLAGS="-fno-section-anchors" ./ --gmp-version=5.0.3 --mpfr-version=3.0.1 --mpc-version=0.9 --binutils-version=2.22.51 --gdb-version=7.4 --mingw $BASE_DIR/toolchain-src $BASE_DIR/android-ndk-r7 arm-linux-androideabi-4.6.2

Once the build is finished, your toolchain is in BASE_DIR/android-ndk-r7/toolchains/arm-linux-androideabi-4.6.2/prebuilt/windows

BTW: This build system can now be used to build both windows & linux binaries. Just add or remove --mingw from the ./ command.


  • Compiler
    • Fix #120
    • Run unittests
  • druntime
    • Uses __get_stack_base instead of __libc_stack_end. It should be tested to verify it is working correctly
    • Building gcc/config/unix.d fails, so the patch simply skips that file. This should be investigated further and fixed correctly.
    • druntime depends on some functions which are not in bionic. It builds, but user apps don't link.
  • phobos
    • disabled for now