Installing Cross Compiling Tools for Raspberry Pi Part 1

Ames Computers Geek Corner News Installing Cross Compiling Tools for Raspberry Pi Part 1 NYC New York City North Bergen County
https://www.raspberrypi.org/

Compiling a large project on a raspberry may take days compared to several minutes on a x86 CPU. The Raspberry Pi has very little RAM. In comparison, cross-compiling and linking the same code on a modern machine takes a fraction of the time. Since we are going to run on an Intel processor, and we want to build object code for the ARM processor for the Raspberry Pi, we need a cross-compiler and its associated tools, which is usually called a toolchain. We will be using crosstool-ng to build the toolchain. While there are a lot of different methods for building cross-compilers, the quickest and easiest is to use crosstool-ng. This is a set of scripts that bring up a menuconfig-like interface to choose your compiler settings, then goes off and downloads what it needs, patches it, configures it, builds it and installs it all for you.

First, we need to create a directory to host, download and extract the sources. Create a directory in your home directory called src. We will be storing all the files needed for cross compiling there. Inside the directory, create a directory called toolchain, where we will store all the toolchains. Download the crosstool-ng there from crosstool-ng.org. Once downloaded, extract the files and go to the extracted directory. Run ./configure --prefix=/opt/cross where /opt/cross stores the executables for the cross compiler. Make sure that /opt/cross/bin is in your HOME environment variable. Then finally, run make and install to install the crosstool-ng.


To configure crosstool-ng, we need to run ct-ng menuconfig which will bring up the configuration menu. Go into Paths and misc options. Enable Try features marked as EXPERIMENTAL. Go back to the main menu and select Target options. Change the Target architecture to arm. Leave Endianness set to Little endian and Bitness set to 32-bit. Go back to the main menu and select Operating system. Change Target OS to linux. Go back to the main menu and select Binary utilities. Change binutils version to whichever is the latest that isn't marked as experimental. Go back to the main menu and select C compiler. Enable the Show Linaro versions (EXPERIMENTAL) option. n the gcc version field, choose the linaro-4.6-2012.04 (EXPERIMENTAL) compiler. All the other settings are fine left at their default values. Exit the configuration tool and save your changes. Run ct-ng build.

In order to get the cross compiler to work, we also need to install some other tools. We need bison which is a general purpose parser generator. Cvs which is used to store the history of a file. We need flex which is a open source lexical analyzer generator. We need gperf which is a hash generator. We need texinfo and texinfo and libtool. In Linxu, you can install them all by running sudo apt-get update and then sudo apt-get install bison cvs flex gperf texinfo automake libtool. Once the tools are installed, run make and make install.