The BeagleBone Black - A Low-Cost Embedded Platform, Part 2

The BeagleBone Black - A Low-Cost Embedded Platform, Part 2

Wednesday, March 12, 2014

In part one of this series I introduced the BeagleBone Black, a low-cost embedded computer platform that supports Qt. In this second blog post, I'll look at how to get Qt 4 up and running on this hardware.

Introduction

The BeagleBone Black can run a number of different operating systems, but most users are likely to use it to run some version of embedded Linux, as it was designed as a platform for Open Source software.

Out of the box, it runs the Ångström Linux distribution. Another popular operating system choice is Ubuntu Linux. I'll use these two distributions as examples in this blog post. Other Linux distributions should be similar, particularly Debian, which which Ubuntu is derived. I won't cover using Qt when running Android. While it should be possible, it is more complex and beyond the scope of what I can cover here.

You have at least three options for getting Qt 4 up and running on the BeagleBone Black, each of which I will cover here:

  1. Use pre-built Qt packages for your Linux distribution
  2. Compile Qt 4 yourself on the BeagleBone Black
  3. Cross-compile Qt 4 on a fast desktop computer

We'll now look at each of these approaches in detail.

Pre-Built Packages

Qt is quite large and takes time to build. Configuration can also be somewhat complex. On desktop systems, many users of Qt use the Qt binary packages available for their Linux distributions. Both Ångström and Ubuntu for the BeagleBone Black offer pre-built Qt 4 packages that can be installed from the distribution package servers.

Assuming you have your unit running the Ångström distribution and have an Internet connection to the package servers, the following commands, run as the root user, will install Qt 4:

    opkg update
    opkg install qt4-x11-free

This will give you a basic install of the Qt libraries. If you want to prepare for a development projejct, you will likely also want to install the package qt4-x11-free-dev and possibly also the developer documentation package qt4-x11-free-doc. Before using the Qt development tools like qmake you need to set up the environment for running them by executing the following command:

    source /usr/share/qt4/environment-setup

Note that the development and documentation packages are quite large so you will need enough free space on your system to hold them. The BeagleBone's internal 2 GB flash may not be large enough to include the development packages and documentation so you may need to add additional storage. Currently the version of Qt offered is Qt 4.8.1.

On Ubuntu for the BeagleBone Black, Qt packages are available just like on Ubuntu desktop systems. For example, under Ubuntu Raring (13.04), you can get a basic Qt 4 install using these commands:

    sudo apt-get update
    sudo apt-get install qt4-default

To perform development you will also want to also install, at minimum, the packages g++ and make. If you are not running a desktop environment with X11, a minimal setup can be installed by installing the packages xorg and openbox. Running startx from a text console will start up the X server and Openbox window manager. The above should fit in the 2 GB on-board flash but you'll want a larger filesystem to do any significant development work. Under the Ubuntu Raring release, the version of Qt is 4.8.4.

Below is a screenshot of a Qt 4 spreadsheet example program running under Ubuntu and the Openbox window manager.

What are the pros and cons of using pre-built Qt packages? On the plus side, it is fast and easy and avoids having to go through the time and effort to configure and build Qt yourself.

The disadvantages are that the very latest version of Qt 4 (Qt 4.8.5 at the time of writing) may not be available, and the pre-built packages may not be optimal for your application. For example, they may include more components than you need or not be in the install location you desire, or you may want to use a different graphics back end than X11.

Build Natively

The second option is to build Qt natively on the BeagleBone Black. As it is running a Linux-based operating system, it can be compiled on the hardware just like on a desktop system. You will need to install the g++ compiler and other development packages needed to build Qt. Then download the Qt 4 source code, extract it, and run the configure script with suitable options.

The advantage of this approach is that it's quite simple and gives you the flexibility to configure Qt exactly as needed for your application. The main downside is that compiling on the BeagleBone Black is much slower than on a modern desktop system, as it is only a single core 1 GHz ARM CPU. A full build of Qt 4 on my main desktop system, a typical laptop, takes under thirty minutes. The same build of Qt 4, including QtWebKit and the demos and examples, takes about twenty-four hours when built natively on the BeagleBone Black. If you need to build Qt several times with different configure options, it can consume a lot of time.

Cross-Compile on a Desktop Computer

The third option, in order of increasing complexity, is to cross-compile Qt on a fast desktop computer. Cross-compilation is generally the norm when developing for embedded systems, many of which are not even capable of compiling code natively on the embedded hardware.

Depending on your platform, some type of cross-compiler SDK is typically offered. At a minimum, you need a cross-compiler. In most cases, it is more convenient to use an embedded framework that supports more features for cross-development, like building packages.

Ångström Linux uses OpenEmbedded as its framework. OpenEmbedded is part of the larger Yocto project and use BitBake as its primary software-building tool. While a full description of Yocto, OpenEmbedded and BitBake is beyond the scope of this blog post, I'll give brief instructions on how to build Qt 4 using these tools. References 2, 3 and 4 listed at the end give more background information and details.

The following commands will check out the build scripts used by Ångström Linux, configure them for a BeagleBoard and build Qt 4 for X11. These commands should work on any recent Linux desktop such as Ubuntu:

    git clone git://github.com/Angstrom-distribution/setup-scripts.git
    cd setup-scripts
    MACHINE=beagleboard ./oebb.sh config beagleboard
    MACHINE=beagleboard ./oebb.sh update
    MACHINE=beagleboard ./oebb.sh bitbake qt4-x11-free

Because it also builds all of the dependencies for Qt 4, the above may take a few hours initially to build. The result, if successful, should be a set of Qt 4 packages suitable for installing on a BeagleBone Black. The packages should appear in a directory (relative to where you built the above) called deploy/eglibc/ipk/armv7ahf-vfp-neon. The ipk files are packages, similar to Debian or Ubuntu packages, which can be installed by transferring them to the BeagleBone Black and using the opkg command.

Currently, the Qt 4 packages in Yocto default to version 4.8.4. As well as using X11, there are BitBake recipes for building Qt to use a frame buffer for display output and for building the optional Qt Mobility module.

While the cross-compilation approach takes time to set up and become familiar with it, once in place you can be much more productive developing on a fast desktop system that is more comfortable for editing and much faster to compile. As a data point for compilation speed of a Qt application, the spreadsheet example I mentioned earlier took over seven minutes to compile natively on the BeagleBone Black and only eleven seconds to compile locally on a desktop system (the full build process, including packaging, takes longer using BitBake, but the difference is still quite dramatic).

Summary

In this blog post, I described some different approaches for getting Qt 4 running on the BeagleBone Black. In part three we'll examine how to set up Qt 5 on this platform.

References

  1. angstrom-distribution.org, Ångström Linux distribution website
  2. openembedded.org, OpenEmbedded Project website
  3. yoctoproject.org, Yocto Project website
  4. angstrom-distribution.org/toolchains, Toolchains for cross-compiling

Interested in Qt & QML?

Read more articles from the category Qt & QML

About the author

Jeff Tranter

Bio:

Jeff Tranter is a Qt Consulting Manager at ICS. Jeff oversees the architectural and high-level design of software systems for clients. Jeff’s leadership organizes global teams of developers on desktop and embedded applications.