I wrote this how to because I'm experimenting with writing my own operating system and I needed to build a cross compiler for this. I had a hard time learning how to do this but it's quite simple.
You will need to download the following packages from http://ftp.gnu.org/gnu/
binutils 2.22
gcc 4.6.2
(this is only for C, if you want support for C++ or any other language you will need to download it from http://ftp.gnu.org/gnu/gcc/)
gmp 5.0.4
mpfr 3.1.0
mpc 0.8.2
Extract the files
We want to create build directories so we don't clutter our source
Let's set our environment variables
Obviously this is for i586-elf, you can make the target for whatever your needs are. This is beyond the scope of this howto but I do know that if you are trying to build a 64 bit elf compiler you can substitute i586-elf with x86_64-elf you should be able to elf with arm or whatever it is your trying to build for.
First we want to build binutils
Now that binutils is installed we will need to install gcc's dependencies
Now that everything has been built we can take care of gcc
This installs your cross compiler under /usr/local/cross.
After this is all done you should build a C Library but that's for another time. Most of this information was pieced together from http://wiki.osdev.org/GCC_Cross-Compiler but made to fit for FreeBSD.
This is my first EVER howto so please, be kind Give me any suggestions and I'll change this as errors pop up.
-Kris
You will need to download the following packages from http://ftp.gnu.org/gnu/
binutils 2.22
gcc 4.6.2
(this is only for C, if you want support for C++ or any other language you will need to download it from http://ftp.gnu.org/gnu/gcc/)
gmp 5.0.4
mpfr 3.1.0
mpc 0.8.2
Extract the files
Code:
$ tar xvf binutils-2.22.tar.gz
$ tar xvf gcc-4.6.2.tar.gz
$ tar xvf gmp-5.0.4.tar.bz2
$ tar xvf mpfr-3.1.0.tar.gz
$ tar xvf mpc-0.8.2.tar.gz
We want to create build directories so we don't clutter our source
Code:
$ mkdir build-binutils build-gcc build-gmp build-mpfr build-mpc
Let's set our environment variables
Code:
export PREFIX=/usr/local/cross
export TARGET=i586-elf
First we want to build binutils
Code:
$ cd build-binutils
$ ../binutils-2.22/configure --target=$TARGET --prefix=$PREFIX --disable-nls
$ make all
# make install
Now that binutils is installed we will need to install gcc's dependencies
Code:
$ cd ..
$ cd build-gmp
$ ../gmp-5.0.4/configure --prefix=$PREFIX
$ make
# make install
$ cd ..
$ ../mpfr-3.1.0/configure --prefix=$PREFIX
$ make
# make all
Now that everything has been built we can take care of gcc
Code:
$ cd ..
$ cd build-gcc
$ ../gcc-4.6.2/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c --without-headers --with-gmp=$PREFIX --with-mpc=$PREFIX --with-mpfr=$PREFIX
$ gmake all
# gmail install
This installs your cross compiler under /usr/local/cross.
After this is all done you should build a C Library but that's for another time. Most of this information was pieced together from http://wiki.osdev.org/GCC_Cross-Compiler but made to fit for FreeBSD.
This is my first EVER howto so please, be kind Give me any suggestions and I'll change this as errors pop up.
-Kris