Jessie armhf Cross Compile: Difference between revisions

From embeddedTS Manuals
No edit summary
(Updated wording)
Line 1: Line 1:
Debian Jessie provides cross compilers, but it does require a Debian Jessie system to be used for the workstation.  A PC, virtual machine, or chroot will need to be used for this.  Download Debian Jessie for your workstation [https://www.debian.org/releases/jessie/ here].
Debian Jessie provides cross compilers, but it does require a Debian Jessie system to be used for the workstation.  A PC, virtual machine, or chroot will need to be used for this.  Download and install Debian Jessie for your workstation [https://www.debian.org/releases/jessie/ here].


From your workstation (not the board), run these commands to set up the cross compiler:
From a Debian workstation (not the target), run these commands to set up the cross compiler:
<source lang=bash>
<source lang=bash>
# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
# Run "lsb_release -a" and verify Debian 8.X is returned.  These instructions are not
Line 15: Line 15:
apt-get install crossbuild-essential-armhf
apt-get install crossbuild-essential-armhf
</source>
</source>
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".
This will install a toolchain that can be used 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:
The toolchain can now compile a simple hello world application.  Create hello-world.c on the Debian workstation:
<source lang=c>
<source lang=c>
#include <stdio.h>
#include <stdio.h>
Line 29: Line 29:
file hello-world
file hello-world
</source>
</source>
This will return that the binary created is for ARM.  Copy this to the armhf distribution to run it there.
This will return that the binary created is for ARM.  Copy this to the target platform 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.
Linking to a shared library from the Debian environment.  Make sure the package that is being linked to is installed on both the Debian workstation and the target platform.  Since armhf architecture support was added previously, it is now possible install armhf packages on the Debian workstation.
<source lang=bash>
<source lang=bash>
apt-get install libcurl4-openssl-dev:armhf
apt-get install libcurl4-openssl-dev:armhf
Line 41: Line 41:
</source>
</source>


You should be able to execute this from the board now. Using the curl library that will be loaded at runtime from the board.
The binary can now be copied over to the target platform and executed using the curl library that will be loaded at runtime from the target.


If your binaries do not rely on hardware support like GPIO or CAN, you can run your binaries using qemu.
If any created binaries do not rely on hardware support like GPIO or CAN, they can be run using qemu.
<source lang=bash>
<source lang=bash>
# using the hello world exampel from before:
# using the hello world example from before:
./hello-world
./hello-world
# Returns Exec format error
# Returns Exec format error

Revision as of 17:25, 29 December 2016

Debian Jessie provides cross compilers, but it does require a Debian Jessie system to be used for the workstation. A PC, virtual machine, or chroot will need to be used for this. Download and install Debian Jessie for your workstation here.

From a Debian workstation (not the target), run these commands to set up the cross compiler:

# 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 that can be used with the prefix "arm-linux-gnueabihf-". All of the standard GCC tools will start with that name, eg "arm-linux-gnueabihf-gcc".

The toolchain can now compile a simple hello world application. Create hello-world.c on the Debian workstation:

#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 target platform to run it there.

Linking to a shared library from the Debian environment. Make sure the package that is being linked to is installed on both the Debian workstation and the target platform. Since armhf architecture support was added previously, it is now possible install armhf packages on the Debian 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

The binary can now be copied over to the target platform and executed using the curl library that will be loaded at runtime from the target.

If any created binaries do not rely on hardware support like GPIO or CAN, they can be run using qemu.

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