BBB Cross Compiler

From Klaus' wiki
Jump to: navigation, search

A few things are needed in order to set-up development of programs, that shall execute on an ARM platform. You'll need a cross compiler - a compiler that can generate ARM executable code while the compiler is executed on the PC platform, which is typically a Intel X86_64 architecture.

Cross Compiler

Neither the Fedora nor the Centos package system includes a suitable compiler for the ARMv7 processor.

Luckily Linaro, does maintain a toolchain suitable for us. At this point you can find the newest binaries for your operating system. At the end of the displayed list is a link to the newest versions. Click on the newest. Click on arm-linux-gnueabihf and in the next screen select gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz where the letters match release number and date.

The following is suited for Centos/Fedora Linux and probably other Linux'es as they are rather generic.

]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/V.v-20YY.MM/arm-linux-gnueabihf/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz

change the n, m, x, YY and MM with the current version. (NOTE: It seems as if the verion 6.2.something causes troubles.)

I keep downloaded tools in the /opt directory rather than in the /usr/local or other places in the /usr tree.

Notice: Use the correct version number below.

]$ cd /opt
]$ mkdir toolchains
]$ cd toolchains
]$ tar Jxvf ~/Downloads/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz
]$ ln -s gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf/ gnueabihf
]$ file gnueabihf/bin/arm-linux-gnueabihf-gcc

These commands will create a toolchains directory in /opt and unpack the downloaded binaries into a structure. A symbolic link gnueabihf is created. This link can later be changed if a newer version of the compiler and libraries are downloaded.

The last command is just for ensuring that you've got the correct package downloaded. Expect something like this:

[klaus@klaus-x230 bin]$ file arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter 
/lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=71722376ff3af9eee5caf7bdfa2ecc350db0a590, not stripped
[klaus@klaus-x230 bin]$

Develop a Cross Compiled Program

Start Eclipse and create a new project:

RemoteDebugging.png

Notice the settings for the Cross GCC

On one of the next dialogues you have to specify what the prefix for the cross compiler tools are and where they resides.

RemoteDebugging1.png

In the project create a new C source file and fill in some "Hello World" stuff.

Save and compile (Ctrl+S, Ctrl+B).

In a console go to <path to your project>/Debug

]$ file <your binary (project name)>

Expect something like this:

[klaus@klaus-x230 Debug]$ file TestRemoteDBG 
TestRemoteDBG: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, 
interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.16, BuildID[sha1]=e8baff7637d637533f3730021407ffdc6d4c314e, not stripped
[klaus@klaus-x230 Debug]$ 

This tells us that the compiler has produced ARM executable code.