Difference between revisions of "BBB Cross Compiler"

From Klaus' wiki
Jump to: navigation, search
(Cross Compiler)
Line 12: Line 12:
<source lang=bash>
<source lang=bash>
]$ cd ~/Downloads
]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/runtime-linaro-gcc4.9-2016.02-arm-linux-gnueabihf.tar.xz
]$ wget https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz

Revision as of 12:44, 8 March 2018

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

The Fedora package system does not contain 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. Go up the directory structure to discover if a newer compiler has been released.

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

For BBB running kernel version 3.8.x use this:

]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz

For BBB running kernel verison 4.x use this:

]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/6.2-2016.11/arm-linux-gnueabihf/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz

which will download the newest version on the time of writing this.

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-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz
]$ ln -s gcc-linaro-6.2.1-2016.11-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:


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