Step 3.2. Cross-compilation (Omega OS)

The most interesting for us is a case of cross-compiling the application. This step provides an example of configuring and compiling this project via a third-party SDK using the Linux OpenWRT SDK for a single-board minicomputer Onion Omega2+.

The Omega 2 single-board computer provided with pre-installed its own Linux Onion OS operating system, which has a lot of limitations and unfortunately the vendor does not provide a convenient ready-to-use SDK.

To use it we need to compile Onion SDK from sources. Docker's variant is not working on Windows 10 Home Edition. In this step it is no need!

Onion OS is based on another operating system OpenWRT 18.06 which has the SDK (it already compiled for MIPS architecture and processor Mediatek MT7688 as our Omega2 builded). It ready to run on a x86-x64 host architecture. Therefore, the fastest way to create cross-platform user space applications is download OpenWRT 18.06 SDK x86_x64 MIPS MT76x8

Now let's begin cross-compiling.

Select a convenient SDK installation directory in the host (x86/x64) and go to it. By the known link OpenWRT SDK x86_x64 MIPS MT76x8 we find the archive file .tar.xz with the text "-sdk-", download, unpack; example below:

wget https://downloads.openwrt.org/releases/18.06.2/targets/ramips/mt76x8/openwrt-sdk-18.06.2-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64.tar.xz tar -xf ./openwrt-sdk-18.06.2-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64.tar.xz mv ./openwrt-sdk-18.06.2-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64 ./openwrt-sdk-mt76x8

Go back to the folder with the template project (hello world). You need to edit file configure-mips-openwrt.sh and write your own SDK paths. Below are the lines from my file that will need to be changed.

# define the pathes (by default) to the buildroot BUILDROOT_PATH="/home/vladimir/OpenWRT-sdk" # define the toolchain and target names ... TOOLCHAIN_DIR="$STAGING_DIR/toolchain-mipsel_24kc_gcc-7.3.0_musl" TARGET_DIR="$STAGING_DIR/target-mipsel_24kc_musl"

Once properly edited this file it can be applied to other projects with the same SDK's paths without changes.

Now you need to run configure script, through the previously edited script configure-mips-openwrt.sh. It's important!

./configure-mips-openwrt.sh

If all paths are correct, there should be no errors, working files will appear from the blank files with the suffix .in.
In the cross-compilation case (using SDK), you will find script file xmake.sh (see details below).

NOTICE: The configure script (configure-mips-openwrt.sh) can accept arguments, for more details see the relevant documentation

WARNING: In cross-compilation case the configure script incorrectly sets the installation paths, set it by hand via command-line arguments, type key --help for help.

Cross-compilation via SDK. The last thing is running the make utility through the script xmake.sh.

./xmake.sh

NOTICE: xmake.sh supports command-line arguments that are passed to the make utility.

That's all!

And last you can easy switch compilation of your application between Linux host x86/x64 and Onion OS by run configure or configure-mips-openwrt.sh at any time.