Jessie armhf Cross Compile

From embeddedTS Manuals
Revision as of 11:11, 28 August 2015 by Mark (talk | contribs)
# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
# expected to work on any other version or distribution.

apt-get install curl build-essential

su root
echo "deb http://emdebian.org/tools/debian jessie main" > /etc/apt/sources.list.d/emdebian.list
curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
dpkg --add-architecture armhf
apt-get update
apt-get install crossbuild-essential-armhf

This will install a toolchain you can use with the prefix "arm-linux-gnueabihf-". All of the standard GCC tools will start with that name, eg "arm-linux-gnueabihf-gcc".

You can test out thet toolchain with a hello world. Create your hello-world.c with your preferred editor:

#include <stdio.h>
int main(){
    printf("Hello World\n");
}

To compile this:

arm-linux-gnueabihf-gcc hello-world.c -o hello-world
file hello-world

This will return that the binary created is for ARM. Copy this to the armhf distribution to run it there.

Now to link to a shared library from the Debian environment. Make sure the package you are linking to is installed on both your debian workstation and the board. Since the armhf architecture was added earlier you can install armhf packages on your x86 workstation.

apt-get install libcurl4-openssl-dev:armhf

# Download the simple.c example from curl:
wget https://raw.githubusercontent.com/bagder/curl/master/docs/examples/simple.c
# After installing the supporting library, curl will link just as compiling on the unit.
arm-linux-gnueabihf-gcc simple.c -o simple -lcurl

You should be able to execute this from the board now.

If your binaries do not rely on hardware support like GPIO or CAN, you can run your binaries using qemu.

# using the hello world exampel from before:
./hello-world
# Returns Exec format error
apt-get install qemu-user-static
./hello-world