BBB Cross Compiler

From Klaus' wiki
Revision as of 11:36, 6 November 2019 by Klaus (Talk | contribs)

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

change the V, v, 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-V.v.v-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz
]$ ln -s gcc-linaro-V.v.v-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/, 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:


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.


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/, 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.