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

I’m start­ing a new embed­ded project with ARM7 proces­sor in March so I wanted to play around with the GNU ARM tool­chain. Basi­cally I’m inter­ested in doing cross devel­op­ment on my Mac­book Pro on Mac OS X, using a GCC cross com­piler together with Eclipse CDT. We’ll see if that works out. ;-)

So as a first step, here is how I built a GNU ARM tool­chain on Mac OS X (this should be no dif­fer­ent than build­ing the tool­chain on Linux):

First down­load and unpack the nec­es­sary pack­ages: binu­tils, gcc, newlib and gdb.

$ mkdir ~/crossgcc && cd ~/crossgcc
$ wget ftp://sourceware.org/pub/binutils/snapshots/binutils-2.18.50.tar.bz2
$ tar jxf binutils-2.18.50.tar.bz2
$ wget http://ftp.gnu.org/pub/gnu/gcc/gcc-4.2.3/gcc-4.2.3.tar.bz2
$ tar jxf gcc-4.2.3.tar.bz2
$ wget ftp://sources.redhat.com/pub/newlib/newlib-1.16.0.tar.gz
$ tar zxf newlib-1.16.0.tar.gz
$ wget http://ftp.gnu.org/pub/gnu/gdb/gdb-6.6.tar.gz
$ tar zxf gdb-6.6.tar.gz

The instal­la­tion direc­tory should be /usr/local/crossgcc.

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

First we build the binu­tils:

$ 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 com­piler with C/C++ sup­port:

$ 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 debug­ger:

$ 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 tar­get uClibc is bet­ter. Inter­est­ingly, cross-compiling GNU C++ for uClibc has a compile-time depen­dency for the library itself… so one is required to boot­strap the com­piler, start­ing with a plain C com­piler first. Just my two cents, Micha.

  2. Is there a dif­fer­ence between ARM7 and ARM9 Com­piler?
    I’m try­ing out var­i­ous builds for OLIMEX 9302 and TS-7250 boards, but none really works.
    What are your expe­ri­ences? Did you get a work­ing compiler?

    Kind Regards

  3. I’m try­ing this right now… had no suc­cess at all when com­pil­ing GCC (but I got binu­tils, gmp and mpfr) … hope your instruc­tions work!!

  4. Tuto­r­ial working.

    Note that wget is no longer avail­able under mac os X. (But you can still down­load it from mac ports)

  5. I am try­ing to install the ARM tool chain to Eclipse on a Linux machine. I guess down­load­ing and con­fig­ur­ing the ARM Tool­chain is the first thing I need to do.

    How do I get the com­piled toochain into Eclipse??

  6. Hav­ing been through GMP+MPFR hell, I just have to say, this is a won­der­ful, sim­ple howto that builds the utils with­out prob­lems! Thank you for mak­ing life easy!

    I had *SO* much trou­ble get­ting things work­ing 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 file­name’.
    When/if I got every­thing to work (hope­fully includ­ing some­thing that can trans­fer the code to the board), I’ll put it up on arm.bruger.mine.nu.

  7. I suc­cess­fully built a tool­chain using these instruc­tions, but with the lat­est ver­sions of the util­i­ties: gcc-4.4.2, binutils-2.20.54, newlib-1.18.0 and gdb-7.1. Note that the lat­est ver­sions of GCC require GMP and MPFR to be installed, so I had to do this as well. I haven’t tested the com­piler out just yet as I don’t have a tar­get board to burn at the moment, but I have got­ten every­thing to com­pile and install on Snow Leop­ard (10.6).

  8. Just built a tool­chain using these instruc­tions with gcc-4.7.0, binutils-2.22, gdb 7.4.1, and newlib 1.20.0. A cou­ple minor changes:

    * GCC now requires gmp, mpfr, *and* libmpc, and option­ally ppl. I installed all of these using home­brew.
    * GCC now says the arm-elf tar­get is obso­lete, so I built for the arm-eabi tar­get. You can still build for the arm-elf tar­get with –enable-obsolete (or maybe –with-obsolete) though.

  9. Excel­lent guide. I man­aged to build the tool­chain ‚and even com­pile a lit­tle hi.cpp but when I run on the rasp­berry pi I get a Ille­gal Instruc­tion … :(

    Any point­ers ?

    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 com­pile with:
    arm-none-eabi-g++ –o hi hi.cpp

    which gen­er­ates a file hi

    hi: ELF 32-bit LSB exe­cutable, ARM, ver­sion 1 (SYSV), sta­t­i­cally linked, not stripped

    How­ever if I com­pile directly on the rasp­berry pi I get:

    hi: ELF 32-bit LSB exe­cutable, ARM, ver­sion 1 (SYSV), dynam­i­cally linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

    First time build­ing a cross com­piler tool­chain and actu­ally doing cross com­pi­la­tion, so my knowl­edge is pretty basic

    Here is the out­put when I run on the rap­berry pi

    ./hi
    Ille­gal instruction

Leave a Reply