Building cross compiler tools for RaspberryPi on Mac OSX

[EDIT 2014/12/07] I rebuild a more recent version of the cross-compiler, and I got more trouble this time, so I updated this post with new information.

I have deciding to start developing for Raspberry Pi. As I use Mac OSX, I needed to build my own C cross compiler, because those provided on the RaspberryPi GitHub project only work for Linux.

At first, I wanted to build it from scratch, but after 2 days of failure, I decided to use crosstool-ng; apparently other people had succeeded building a cross compiler for RaspPi with it. But once again, it wasn’t so easy, I went to some troubles. But I finally succeeded to. So here is a full explanation on how I did.

First of all, you need HomeBrew, to install some needed package, and to install crosstool-ng itself. You can find it here :

Then from brew, install crosstool-ng, it will install all (or almost all) needed packages :

brew install crosstool-ng

Then install grep from brew :

brew tap homebrew/dupes
brew install homebrew/dupes/grep

We will also need gettext, for glibc build.

brew install gettext
brew link --force gettext

Also, you will need XCode command line tools :

xcode-select --install

You then have to tell crosstool-ng to use this grep instead of Apple’s one. For this you have to edit file, it should be located somewhere like /usr/local/Cellar/crosstool-ng/1.20.0/lib/ct-ng.1.20.0/ Edit the file and replace the line export



export grep="/usr/local/bin/ggrep"

This should do the trick. Now you are ready to use crosstoll-ng, or maybe, not exactly. crosstool-ng needs a case sensitive filesystem, and by default, Mac OSX  partitions are not; so you have to create one. Don’t worry, you don’t really have to create and new partition and mess up your hard drive. Open Disk Utility, and choose File > New > Blank Disk Image. You have to repeat the operation twice; because you have two create to images, one to build the cross compiler, and one to store the cross compiler. The one to build must be almost 5 GB (4,7GB for me), the other one only few hundreds of MB (about 200MB). Choose Mac OS Extended (Case-sensitive, journalized) for file format.

Go on the 1st image created, the bigger one, it will be used for the build. Start configuring your cross compiler :

ct-ng menuconfig

This will open a menu to edit the configuration, choose the following options :

  • Paths and misc options
    • enable ‘Try features marked as EXPERIMENTAL’
    • Prefix directory : /Volumes/BuildTools/x-tools/${CT_Target}) , where you want to install the cross tools once build. This must be on the 2nd image you created, because it must also be a case sensitive filesystem.
    • Extra host compiler flags : -fbracket-depth=1024
  • Target options
    • Target architecture : arm
    • Enable ‘Use the MMU’
    • Endianness : Little Endian
    • Bitness : 32 bits
    • Architecture level : armv6zk
    • Emit assembly for CPU : arm1176jzf-s
    • Tune for CPU : arm1176jzf-s
    • Use specific FPU : vfp
    • Floating point : hardware FPU
  • Toolchain options
    • Tuple’s vendor string : rpi or whatever you want, it will be added in the name of the binaries created
  • Operating system
    • Target OS : linux
    • Linux kernel version : 3.12.24 (this must be the version you have on your Raspberry Pi, or close to)
  • Binary utilities
    • binutils version : 2.24
  • C compiler
    • Enable ‘Show Linaro versions’
    • gcc version : 4.9.1 (you can try an other one, this one worked for me)
    • Enable ‘C++’
  • C library
    • C library : glibc
    • glibc version : 2.19
  • Companion libraries
    • change GMP version to 5.0.2, there is a problem with version > 5.1 and PPL library
  • Debug facilities
    • Enable gdb (if you want to cross debug)

You can now exit the menu, it will save the configuration file under .config.

Open now the .config file with a text editor, and find the line ‘CT_CC_STATIC_LIBSTDCXX=y’, change it to ‘CT_CC_STATIC_LIBSTDCXX=n’.

One last thing to do before starting : the build opens a lot of files in parallel, and on my machine it was more that what was allowed, so you have to change this :

ulimit -n 1024

Now launch the build a first time:

ct-ng build

You must have an error at step “Installing C library headers”, saying

Undefined symbols for architecture x86_64: 
"_libintl_setlocale", referenced from:
_main in cross-rpc_main.o.

We have to patch a makefile for this; so edit the file “.build/src/glibc-2.19/sunrpc/Makefile” and add a line

BUILD_LDFLAGS += -L/usr/local/lib -lintl

Start the build again, and this should work. It will take quite a long time, about 30 minutes for me, so you can have a coffee now !