-
Couldn't load subscription status.
- Fork 1
Setting up cross compilation tool chain
Arjun edited this page Apr 26, 2019
·
10 revisions
The cross-toolchain repository on linux can be used for crosscompilation. Specifically, the ARM hard float (armhf) package can be used for building programs for the BBB.
- On the guest OS (Debian on VM), run the following command:
sudo apt install crossbuild-essential-armhf
- Test installation by calling it directly:
arm-linux-gnueabihf-g++ -v - You should see the following output:
“COLLECT_GCC=arm-linux-gnueabihf-g++ … Thread model: posix gcc version 6.3.0 20170516 (Debian 6.3.0-18) ”
To test the tool chain, create a simple hello world program and cross-compile for ARM.
nano testcross.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, From amrhf architecture!";
return 0;
}- Compile with -static to statically build the executable.
user@desktop:~$ arm-linux-gnuabihf-g++ -static testcross.cpp -o testcross
- The above code will produce an executable file called
testcross. This will not directly run on your computer since it has ARM machine code. You should see the following error if you try:cannot execute binary file: Exec format error - Copy the testcross file on to the BBB.
- Run the program in BBB using:
./testcross
- It should print:
Hello, From amrhf architecture!
The cross compiled programs cannot be run on your computer (or Guest OS) since it has machine code for the ARM architecture. However, QEMU package can be used to emulate the armhf on the guest OS in VM. To do this:
sudo apt install qemu-user-static- Notify dpkg (package management system) that multiple architecture packages will be on the machine.
user@desktop:~$ sudo dpkg --add-architecture armhf
user@desktop:~$ dpkg --print-foreign-architectures
armhf ”
- Check for success with:
user@desktop:~$ sudo apt update - Return should have several packages ending in
armhf Packagesif not try again. - You can also try running the
testcrossexecutable created in the prev section to verify that QEMU is installed correctly.