Posts Tagged ‘x86’

Building gcc as cross-compiler


A cross-compiler is a compiler that runs on your PC and reads source code in your PC and converts that into binary suitable for some other CPU. Sometimes the precise cross compile tool may not be available as a binary package. For example, in my case i wanted to use bare-metal x86 tools(To build BIOS or similar low level system software). It was not available as binary package. Hence only option is to build it.


The packages and libraries needed to build gcc are well documented along with gcc. If you usually build softwares on your linux build PC, there are not much extra dependencies on the PC. One important dependency to build cross gcc is you should already have cross binutils for the same platform. And the binaries especially linker(ld) and assembler(as) should be available in the path. Eg. to build i686-elf-gcc, i686-elf-ld and i686-elf-as should be available in the system path. So

  1. Step 1 is to build binutis
  2. Step 2 is to build gcc

Further I will list the steps needed to build the cross gcc; specifically the i686-elf variant

Step 1: Build binutils as cross-tool

Download binutils. Extract, configure from a separate build directory, build and install it using following commands.

tar -xvf binutils-2.26.tar.bz2
mkdir build_binutils
cd build_binutils
../binutils-2.26/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --with-sysroot
make install
cd ..

All binaries will be available in the path specified in <path-to-bin>

Step 2: Build gcc as cross-tool

First set the path to binutils executables that got generated in the previous step.


Download, extract, configure from a separate build directory, build and install it using following commands

tar -xvf
mkdir build_gcccd build_gcc
../gcc-gcc-4_9_3-release/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

All binaries and libraries generated will be available in path specified in <path-to-bin>


OSDev: GCC Cross-Compiler

OSDev: GCC tool naming/prefix convention

Categories: Log, Tech Tags: , , ,