Jessie armhf Cross Compile: Difference between revisions
(Created page with "# 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-esse...") |
No edit summary |
||
Line 1: | Line 1: | ||
<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 | ||
# expected to work on any other version or distribution. | # expected to work on any other version or distribution. | ||
Line 10: | Line 11: | ||
apt-get update | apt-get update | ||
apt-get install crossbuild-essential-armhf | apt-get install crossbuild-essential-armhf | ||
</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". | |||
You can test out thet toolchain with a hello world. Create your hello-world.c with your preferred editor: | |||
<source lang=c> | |||
#include <stdio.h> | |||
int main(){ | |||
printf("Hello World\n"); | |||
} | |||
</source> | |||
To compile this: | |||
<source lang=bash> | |||
arm-linux-gnueabihf-gcc hello-world.c -o hello-world | arm-linux-gnueabihf-gcc hello-world.c -o hello-world | ||
file hello-world | file hello-world | ||
</source> | |||
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. | |||
<source lang=bash> | |||
apt-get install libcurl4-openssl-dev:armhf | apt-get install libcurl4-openssl-dev:armhf | ||
Line 28: | Line 36: | ||
# After installing the supporting library, curl will link just as compiling on the unit. | # After installing the supporting library, curl will link just as compiling on the unit. | ||
arm-linux-gnueabihf-gcc simple.c -o simple -lcurl | arm-linux-gnueabihf-gcc simple.c -o simple -lcurl | ||
</source> | |||
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. | |||
<source lang=bash> | |||
# using the hello world exampel from before: | |||
./hello-world | |||
# Returns Exec format error | |||
apt-get install qemu-user-static | |||
./hello-world | |||
</source> |
Revision as of 11:11, 28 August 2015
# 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