Skip to content

Linux crosscompiler for the BBB

Franz Miltz edited this page Aug 7, 2021 · 1 revision

Linux crosscompiler

This will help you massively speed up compilation when you want to run the system on a BBB.

Installation

Install g++-arm-linux-gnueabihf:

sudo apt install g++-arm-linux-gnueabihf

Usage

Add CROSS=1 to your make command and run it on your PC - not the BBB! You may also want to add the -j flag to take advantage of your multi-core CPU (that's where much of the speedup over BBB comes from). For example:

make -j CROSS=1

If you have mounted the BBB file system using sshfs, you can now execute ./hyped on the BBB, like you normally would.

If you compile the code locally on your pc, you can copy the executable to the BBB using scp. For example:

scp hyped hyped@192.168.6.2:<DIRECTORY YOU WANT TO COPY TO>

Some extra background info

The silicon inside a CPU does not "speak" C++ (or any other programming language). However, it does speak a language of 0s and 1s (which is still quite incredible). Such CPU language is called instruction set. It is the compiler's job to translate C++ (or another language) to the instructions from an instruction set.

(An instruction is a sequence of 0s and 1s. Part of the sequence tells the CPU what kind of action to perform (e.g. add two numbers or load a value from memory). The rest of the sequence may contain "arguments" such as a memory address from which to load a value.)

All the Intel and AMD CPUs speak the x86 instruction set. However, the BBB has an ARM processor (so does your phone btw) which has a very different instruction set. This means that a program compiled for one platform, will not run on another - an executable consisting of x86 instructions will look like a complete garbage to an ARM CPU and vice versa.

Even the compiler itself is just a program consisting of the binary instructions. Hence, when you install g++ (the compiler we use) or any other program, you always get the version which can run on the CPU of the machine you install it to. When it comes to compilers, they normally translate a high level programming language into the instruction set they themselves consist of. So if you get a compiler that runs on your machine, it's outputs will also run on the same machine. Quite sensible, isn't it?

But BBB has a slow CPU which takes ages to compile the HYPED software. Hence we would like to use the much more powerful CPU of any laptop or desktop. The crosscompiler above is a binary in x86 but it translates C++ into the instruction set used by ARM CPUs. So you can run the crosscompiler on your PC but not on the BBB and you can run its output on the BBB but not on your PC.

Clone this wiki locally