Cross compiler

13 Jun 2012

For simplicity, I chose to set up a so-called cross compiler for osdeving. In OSX Lion, this is what I did.

First of all, I installed Xcode from the Mac App store. Since version 4.3, Xcode doesn't install any command line tools anymore, so this had to be done manually:

  • Open Xcode
  • Go the Preferences
  • Choose Downloads
  • Find Command Line Tools and click Install.

This is better than some earlier versions, though, which use a buggy c-compiler. An update was required on one of my computers.

Compiling gcc also requires the mpfr package to be installed. This I did with Homebrew.

$ brew install mpfr

I downloaded all the sources I needed from

$ curl -O
$ curl -O
$ curl -O
$ curl -O
$ curl -O

Feel free to use later versions, but if you do, I cannot guarantee that the code posted in my logs will work for you (it's very likely to work, but not guaranteed). Gmp, mpfr and mpc are floating point libraries that are used by gcc, so after extracting all archives, they are simply copied into the gcc source

$ mv gmp-5.0.2 gcc-4.6.3/gmp
$ mv mpfr-3.1.0 gcc-4.6.3/mpfr
$ mv mpc-0.9 gcc-4.6.3/mpc

In order not to mess up the source, binutils and gcc were built out of tree.

$ mkdir build-binutils
$ cd build-binutils
$ export PREFIX=/usr/local/cross
$ export TARGET=i386-elf
$ ../binutils-2.22/configure --target=$TARGET --prefix=$PREFIX --disable-nls
$ make all
$ make install

And the same for gcc, using the new binutils

$ cd ..
$ mkdir build-gcc
$ cd build-gcc
$ export PATH=$PATH:$PREFIX/bin
$ ../gcc-4.6.3/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers
$ make all-gcc
$ make install-gcc

It's really important to run make all-gcc and make install-gcc and not make all and make install here. It probably works anyway - if you ever manage to get it to actually compile...

And that's it!


comments powered by Disqus
© 2012 Thomas Lovén - @thomasloven - GitHub