Building a GNU ARM cross-compiler toolchain on Mac OS X

I’m starting a new embedded project with ARM7 processor in March so I wanted to play around with the GNU ARM toolchain. Basically I’m interested in doing cross development on my Macbook Pro on Mac OS X, using a GCC cross compiler together with Eclipse CDT. We’ll see if that works out. 😉

So as a first step, here is how I built a GNU ARM toolchain on Mac OS X (this should be no different than building the toolchain on Linux):

First download and unpack the necessary packages: binutils, gcc, newlib and gdb.

$ mkdir ~/crossgcc && cd ~/crossgcc
$ wget
$ tar jxf binutils-2.18.50.tar.bz2
$ wget
$ tar jxf gcc-4.2.3.tar.bz2
$ wget
$ tar zxf newlib-1.16.0.tar.gz
$ wget
$ tar zxf gdb-6.6.tar.gz

The installation directory should be /usr/local/crossgcc.

$ sudo mkdir /usr/local/crossgcc
$ sudo chmod 777 /usr/local/crossgcc

First we build the binutils:

$ mkdir build-binutils && cd build-binutils
$ ../binutils-2.18.50/configure --target=arm-elf \
--prefix=/usr/local/crossgcc/ 2>&1 | tee configure.log
$ make all install 2>&1 | tee make.log
$ export PATH=$PATH:/usr/local/crossgcc/bin

Build the gcc compiler with C/C++ support:

$ cd ../gcc-4.2.3
$ ln -s ../newlib-1.16.0/newlib .
$ ln -s ../newlib-1.16.0/libgloss .
$ cd ..
$ mkdir build-gcc && cd build-gcc
$ ../gcc-4.2.3/configure --target=arm-elf \
--prefix=/usr/local/crossgcc/ --with-newlib \
--with-gnu-as --with-gnu-ld --enable-languages=c,c++ 2>&1 | tee configure.log
$ make all install 2>&1 | tee make.log

Build the gdb debugger:

$ cd ..
$ mkdir build-gdb && cd build-gdb
$ ../gdb-6.6/configure --target=arm-elf --prefix=/usr/local/crossgcc/
$ make all install 2>&1 | tee make.log

16 thoughts on “Building a GNU ARM cross-compiler toolchain on Mac OS X”

  1. Hi Dirk! Newlib is fine for eCos, but with Linux on the target uClibc is better. Interestingly, cross-compiling GNU C++ for uClibc has a compile-time dependency for the library itself… so one is required to bootstrap the compiler, starting with a plain C compiler first. Just my two cents, Micha.

  2. Is there a difference between ARM7 and ARM9 Compiler?
    I’m trying out various builds for OLIMEX 9302 and TS-7250 boards, but none really works.
    What are your experiences? Did you get a working compiler?

    Kind Regards

  3. I’m trying this right now… had no success at all when compiling GCC (but I got binutils, gmp and mpfr) … hope your instructions work!!

  4. I am trying to install the ARM tool chain to Eclipse on a Linux machine. I guess downloading and configuring the ARM Toolchain is the first thing I need to do.

    How do I get the compiled toochain into Eclipse??

  5. Having been through GMP+MPFR hell, I just have to say, this is a wonderful, simple howto that builds the utils without problems! Thank you for making life easy!

    I had *SO* much trouble getting things working on Leopard/PPC, you wouldn’t believe it.

    For those who don’t know yet; instead of wget , you can use curl -O .
    -O switch means ‘keep the filename’.
    When/if I got everything to work (hopefully including something that can transfer the code to the board), I’ll put it up on

  6. I successfully built a toolchain using these instructions, but with the latest versions of the utilities: gcc-4.4.2, binutils-2.20.54, newlib-1.18.0 and gdb-7.1. Note that the latest versions of GCC require GMP and MPFR to be installed, so I had to do this as well. I haven’t tested the compiler out just yet as I don’t have a target board to burn at the moment, but I have gotten everything to compile and install on Snow Leopard (10.6).

  7. Just built a toolchain using these instructions with gcc-4.7.0, binutils-2.22, gdb 7.4.1, and newlib 1.20.0. A couple minor changes:

    * GCC now requires gmp, mpfr, *and* libmpc, and optionally ppl. I installed all of these using homebrew.
    * GCC now says the arm-elf target is obsolete, so I built for the arm-eabi target. You can still build for the arm-elf target with –enable-obsolete (or maybe –with-obsolete) though.

  8. Excellent guide. I managed to build the toolchain ,and even compile a little hi.cpp but when I run on the raspberry pi I get a Illegal Instruction … 🙁

    Any pointers ?

    I used arm-none-eabi as the target

    ../binutils-2.22/configure –target=${TARGET} –prefix=/usr/local/crossgcc/
    ../gcc-4.7.1/configure –target=${TARGET} –prefix=/usr/local/crossgcc/ –with-newlib –with-gnu-as –with-gnu-ld –enable-languages=c,c++

    I compile with:
    arm-none-eabi-g++ -o hi hi.cpp

    which generates a file hi

    hi: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped

    However if I compile directly on the raspberry pi I get:

    hi: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

    First time building a cross compiler toolchain and actually doing cross compilation, so my knowledge is pretty basic

    Here is the output when I run on the rapberry pi

    Illegal instruction

Leave a Reply to Thijs Burema Cancel reply