The second bullet of this week’s 2-Bullet Tuesday! Check out the first bullet here. Subscribe to receive the newsletter on the 2-Bullet Tuesday page!
Omega Tip
Cross-Compiling C & C++ Programs: Part 1 – Setting up the Build System
Last week, we covered how to install gcc
and compile C & C++ programs on the Omega. While this is handy for getting started with C on the Omega, we’ll use a different approach for more complex programs: Cross-Compilation
First of all, what is Cross-Compiling? It is not as complicated as it sounds. Cross-Compiling means creating an executable for a platform that differs from the platform on which compiler is running. Think of a cross-compiler running on a Windows 7 machine, you can create and compile code for Android, iOS, or, in our case, the Omega’s MIPS Processor. So it is a powerful tool that allows us to compile for multiple platforms.
In order to cross-compile, we’ll need to setup the build system that’s used to make the Omega’s firmware and packages. To make this easier for everyone, we’ll show you how to setup a Docker container so you don’t have to make a whole bunch of changes to your system. Then next week, we’ll spend some time compiling programs.
Let us get started with Docker; it is a system for virtual machines and software container platform. What differentiates Docker from other Virtual Machines is that it does not require a specific operating system, only libraries and sets of rules in order to create software to work as desired on any system.
So, there are two key definitions you need to know in order to get started:
- An
image
is a set of files and instructions to create a virtual machine - A
container
is a virtual machine based on an image
Getting closer to the point, let’s focus on DockerHub. It is an online repository of images. It offers a cloud-based service that allows you to access, build and test images. Think of GitHub, it is an online repository for code while DockerHub is an online repository for docker images.
Now it’s time to download, install and setup Docker. Select the download that corresponds to your current operating system. Head to the Docker website and navigate to the bottom of the page and choose your desired download from the third column, it should look something like this:
Please note, Docker for Windows requires Microsoft Windows 10 professional or Enterprise 64-bit. For older versions get the Docker Toolbox and follow the instructions for installation.
Once it’s installed, we’ll need to pull the omega2-source
image from Docker Hub. This is just a dockerized version of our Omega2-customized LEDE build system repo on GitHub.
docker pull onion/omega2-source
Once the image is pulled, we’ll need to run it:
docker run -it onion/omega2-source /bin/bash
Now you are separated from your system, and operating right in the docker container. Since this image is based on our GitHub source
repo, it’s already configured for Omega2 & Omega2+. The last step, to get you to the final destination is to compile everything. Now, on the command line just issue the following:
make
Sit tight as it may take up some time to compile! On older systems, this can take a few hours!
Once the compilation is complete you will be ready to start cross-compiling! Pretty exciting, isn’t it? We will get to actually cross-compiling next week since we’ve covered a lot this week.
Thanks for reading & have a great week!
Have you seen the Omega2S, the smaller and surface-mount version of the Omega2 for high volume commercial and industrial OEMs? See our Omega2S page for more details!
Let us know what kind of stuff you would like to see featured on 2-Bullet Tuesday! Send a tweet to @OnionIoT with your suggestions!
P.S. We’re beyond excited to announce that the Omega2 family is now available on SparkFun!