How to set up Qt Creator to cross compile for embedded Linux
Introduction
This article describes how to build and configure a Qt Creator development environment on Linux to cross compile Qt applications for OpenEmbedded based root file systems. Qt Creator itself can be taken from your distributions repository, or its installer downloaded at Qt website under open-source or commercial licenses.
If you starting with Qt, this article may not provide the best user experience, though it is a comprehensive source of information. For a developer-friendly experience you can either follow:
- Partner Demo Image - Qt for Device Creation - using a pre-built evaluation image provided by The Qt Company and available on the Toradex Easy Installer online feeds.
- Qt Debian Container for Torizon - consider using Torizon for a simplified user-experience.
Qt Licensing Information
Qt is a large framework with different licenses. Licenses also depend on which Qt version is used. Our partner, the Qt Company, can help you find the right license, therefore if you have questions consult the Qt Licensing page for details.
Install the Partner Demo Image - Qt for Device Creation (Boot to Qt) for selected target modules using the Toradex Easy Installer.
Qt 5
Install Qt Creator
Qt Creator provides a complete Integrated Development Environment for application developers to create applications for multiple targets such as embedded systems, mobile devices, desktops. One can install Qt Creator from its installer or from your distribution repository. Choose your option from the tabs below:
To install Qt Creator from its installer, download it according to the chosen license. Make sure that you always have the latest release installed.
Run the installer:
$ ./qt-unified-linux-x64-3.0.5-online.run
It might be necessary to change the installer file mode to executable.
The commercial license enables Qt For Device Creation which provides a set of ready-to-use tools for developing in Qt Creator IDE for embedded systems such as Yocto based Boot to Qt pre-built images and cross-compilation toolchains for a series of target devices (Apalis iMX8 and iMX6, Colibri iMX6 and iMX7). These components must be installed during Qt Creator installation.
For further information about Qt for Device Creation, refer to Partner Demo Image - Qt for Device Creation.
Ubuntu 18.04 provides Qt Creator 4.5.2, which is sufficiently recent for this how-to.
It is preferred that you always use the latest Qt Creator version, available in the tab Qt Creator Installer. Customers using Ubuntu 16.04 LTS have reported issues due to the old version of Qt Creator available from the distribution repository.
sudo apt install build-essential
sudo apt install qtcreator qt5-doc qt5-doc-html qtbase5-doc-html qtbase5-examples
Visit the Qt Creator Manual for further information about the IDE and its features according to the given license.
Once Qt Creator is installed in the host machine, it is necessary to have a Qt-enabled target device image as well as a built Software Development Kit (SDK). At last, this SDK must be configured in Qt Creator in order to build and deploy applications in your target module.
In order to have a Qt enabled target device image and SDK, it is possible to go with one of the following options:
- Qt For Device Creation: a commercial offering that provides the Qt development framework for multiple embedded platforms.
- Build with OpenEmbedded Layers: build a customized image and toolchain based in OpenEmbedded layers and Toradex Linux BSP.
- Boot to Qt for Embedded Linux: build a customized image and toolchain based in Qt layers and Toradex Linux BSP.
Each one of the options has its steps described in the tabs below:
Qt For Device Creation
Build and Deploy the Target Image
For Qt 5, one can install a Boot to Qt pre-compiled evaluation image directly from Toradex Easy Installer. With the commercial license of Qt For Device Creation, you will also get access to the QBSP - the SDK ready-to-use with Qt Creator.
In case Toradex Easy Installer is not available for your module, get your image into an SD card in a couple of clicks going to the Qt Creator top bar option Tools → Flash Boot to Qt device.
Build the SDK for development
We need to have a full Qt toolchain, which provides besides cross GCC and GDB also the Qt headers to include and libraries to link against. With the commercial Qt For Device Creation, you can use the pre-compiled QBSP for evaluation.
Either if you are going to install the pre-compiled QBSP for evaluation, or if you already need to build your own custom QBSP with specific dependencies for your application, please refer to the Boot to Qt installation guides. The article Building Your Own Embedded Linux Image may be particularly useful, especially after the evaluation phase when you must build your own QBSP.
Configure Qt Creator
The QBSP makes it very easy to configure Qt Creator. Read the Qt for Device Creation Installation Guides. For setting-up the pre-compiled QBSP there are two options:
- If you have a Boot to Qt reference target device, you just need to tick a box on the Qt Creator installation (or using the Maintenance Tool), as explained on the Toradex Apalis iMX6 Guide.
- If you have other embedded target hardware, you can download a QBSP from your account on https://account.qt.io/downloads and then use the Maintenance Tool to install it, as explained in the Toradex Colibri iMX6, iMX6ULL and iMX7 Guide.
Build with OpenEmbedded Layers
Build and Deploy the Target Image
For BSP 5, our Reference Images for Yocto Project, more specifically the Multimedia Reference Image, comes with all the Qt5 packages included in packagegroup-tdx-qt5.bb. You can tweak this image to add or remove packages, including Qt5 packages.
For evaluation, you can install the pre-built image from our Toradex Easy Installer feeds. But do notice that we don't provide a pre-built QBSP/SDK for this image, you have to build it by yourself.
Refer to the article Build a Reference Image with Yocto Project to learn how to build and customize the Multimedia Reference Image, and generate an SDK for it.
Legacy information about including meta-qt5 layer
To add Qt5 to oe-core, you have to add the "meta-qt5" layer.
For BSP 2.8 and newer (at least until BSP 5), meta-qt5 is already included by deafult:
${TOPDIR}/../layers/meta-openembedded/meta-multimedia \
${TOPDIR}/../layers/meta-openembedded/meta-python \
${TOPDIR}/../layers/meta-lxde \
${TOPDIR}/../layers/meta-browser \
${TOPDIR}/../layers/meta-qt4 \
${TOPDIR}/../layers/meta-qt5 \
${TOPDIR}/../layers/meta-qt5-extra \
One can build the following image target that contains all Qt5 Packages for BSP 2.8:
- angstrom-qt5-x11-image: for Qt 5 X11 image without desktop
[build] $ bitbake -k angstrom-qt5-x11-image
Starting with V2.6 meta-qt5 is part of the layers that get set up and the manual cloning and change to bblayers.conf are no longer needed.
cd
cd oe-core/stuff
# repository version known to work with V2.1 and V2.2 images
META_QT5=ed05b91f137cb229e9ebababf9f72748aece1bf3
# repository version known to work with v2.4 images (alternatively use HEAD of dizzy branch)
META_QT5=adeca0db212d61a933d7952ad44ea1064cfca747
# repository version known to work with v2.5 images
META_QT5=a610beeee7dd973e544dc67e3598977f5f050b76
git clone --no-checkout https://github.com/meta-qt5/meta-qt5.git
cd meta-qt5
git checkout -b mywork $META_QT5
cd ..
Add the layer to "/oe-core/build/conf/bblayers.conf".
${TOPDIR}/../stuff/meta-openembedded/meta-systemd \
${TOPDIR}/../stuff/meta-openembedded/meta-networking \
${TOPDIR}/../stuff/meta-openembedded/meta-multimedia \
+ ${TOPDIR}/../stuff/meta-openembedded/meta-ruby \
${TOPDIR}/../stuff/meta-lxde \
${TOPDIR}/../stuff/meta-browser \
+ ${TOPDIR}/../stuff/meta-qt5 \
Add Qt5 packages to other image targets
For BSP 5, please use the Multimedia Reference Image as the base for customization, as explained the previous section.
Legacy information for BSP 2.8 about adding Qt5 packages
To build a Qt 5.9 enabled image using BSP V2.8, it is required to add minimal set packages to your ~/oe-core/build/conf/local.conf.
IMAGE_INSTALL_append = " qtbase qtdeclarative qtimageformats qtmultimedia qtquick1 qtquickcontrols2 qtquickcontrols "
The qtbase package has important PACKAGECONFIG options. As an example, if you desire to add QSQLITE driver to your image, it is required to configure this PACKAGECONFIG option accordingly in your local.conf:
IMAGE_INSTALL_append = " qtbase qtdeclarative qtimageformats qtmultimedia qtquick1 qtquickcontrols2 qtquickcontrols sqlite "
PACKAGECONFIG_append_pn-qtbase = " sql-sqlite"
Also, you can search Qt 5 packages using the OpenEmbedded recipes index or by searching the layers directory of your build environment. An example is provided to search for the QtSerialPort package:
$ cd <openembedded-setup-directory>
[oe-core] $ ls
build deploy export layers
[oe-core] $ find ./layers/ -name "qt*serialport*.bb"
./layers/meta-qt5/recipes-qt/qt5/qtserialport_git.bb
Add it along with the other Qt packages in your local.conf
IMAGE_INSTALL_append = " qtbase qtdeclarative qtimageformats qtmultimedia qtquick1 qtquickcontrols2 qtquickcontrols qtserialport "
To include all Qt 5.9 packages using BSP V2.8:
IMAGE_INSTALL_append = " qt3d qt5-plugin-generic-vboxtouch qtbase qtcanvas3d qtcharts qtconnectivity qtdatavis3d qtdeclarative qtenginio qtgraphicaleffects qtimageformats qtlocation qtmultimedia qtquick1 qtquickcontrols2 qtquickcontrols qtscript qtsensors qtserialport qtsvg qtsystems qttools qttranslations qtvirtualkeyboard qtwebchannel qtwebkit-examples qtwebkit qtwebsockets qtxmlpatterns openssh-sftp-server gdb gdbserver "
Information about earlier Qt versions packages
For images starting with BSP V2.7 Qt 5.7, add the following packages
If you need fonts make sure fonts are installed and qtbase is compiled with PACKAGECONFIG fontconfig so they get found.
IMAGE_INSTALL_append = " qtbase qtbase-plugins cinematicexperience liberation-fonts"
PACKAGECONFIG_FONTS_append_pn-qtbase = " fontconfig"
For earlier BSP versions, add the following packages:
IMAGE_INSTALL_append = " qtbase qtbase-fonts qtbase-plugins cinematicexperience"
Other Qt 5 enabled image configurations
For using framebuffer with EGLFS (only supported on iMX6) and building an image without the X11 and LXDE desktop environment, use the console-tdx-image target and add the following to the "build/conf/local.conf" in addition to the above:
DISTRO_FEATURES_remove = "x11 wayland"
IMAGE_INSTALL_remove = "eglinfo-x11"
Every time one changes the DISTRO_FEATURES, one has to remove all build output and sstate cache, in our setup remove the directories build/out* build/sstate-cache or build/tmp* build/sstate-cache deploy, if present from any previous build.
Target Images
After changing your local.conf you may now build either of the following image targets for respective feature set:
- angstrom-lxde-image: for Qt 5 X11 included in our regular Angstrom LXDE desktop environment image
[build] $ bitbake -k angstrom-lxde-image
- console-tdx-image: for Qt 5 with framebuffer EGLFS without X11 included in our regular console image
[build] $ bitbake -k console-tdx-image
This can take several hours. When the build finishes, the image files will be located at "/oe-core/deploy/images/".
Note: For more information concerning how to install your newly built image onto the target have a look at one of the following articles.
Build and Install the SDK for development
You may find it useful to read the Toradex article Build a Reference Image with Yocto Project and The Qt Company article Building Your Own Embedded Linux Image.
Configure Qt Creator
It is recommended that you build a QBSP and and install it as described in the Qt For Device Creation section from this article. If you only build a regular SDK with OpenEmbedded/Yocto, then you may find some tips the legacy information below, though it is not guaranteed to work:
Legacy information for BSP 2.8 about configuring Qt Creator
Before starting Qt Creator, we have to export some build environment variables. Qt uses special configuration files to describe the built environment called mkspecs (they specify which compiler, linker, or other tools to use). However, this configuration files still need to know where the compiler (or cross-compiler in our case) is located. The SDK created a script that does all the hard work.
Using the SDK built with OpenEmbedded layers, source the script to export the environment variables as follows:
. /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi
It is required to source the script to export the environment variables every time in the same terminal session you run Qt Creator.
The environment variable OE_QMAKE_CXX should then show something along this line:
$ echo $OE_QMAKE_CXX
arm-angstrom-linux-gnueabi-g++ -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi
Now, start Qt Creator in the shell where you sourced the script.
Using Qt Creator installed directly from the repository:
qtcreator
For Qt Creator installed from its installer, go to the installation path and run the qtcreator.sh script:
Qt/Tools/QtCreator/bin/qtcreator.sh
It is recommended to source the script that exports the environment variables in qtcreator.sh script.
Add the Target Device
Go to Tools → Options. In the left panel, click on Devices and add a new device representing the target Apalis Module:
- Press Add and choose Generic Linux Device
- Specifiy a name (e.g. Apalis iMX8)
- Fill in the device's IP address
- Authentication on our modules by default: Password, User ''root'', empty password
Add Kit
In the left panel, click on Kits and configure in the following tabs:
- Qt Versions:
- Press Add
- Choose /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/qt5/qmake
- Fill in a name
- Compilers:
- Press Add → Gcc→C++
- Name: G++-LXDE
- Compiler path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-g++
- ABI (should be detected automatically): arm-linux-generic-elf-32bit
- Press Add → Gcc→C
- Name: GCC-LXDE
- Compiler path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gcc
- ABI (should be detected automatically): arm-linux-generic-elf-32bit
- Debuggers:
- Press Add
- Name: GDB-LXDE
- Path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gdb
- Kit
- Press Add
- Name: Toradex Qt Embedded
- Device: Apalis iMX8
- Sysroot: /usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/
- Compiler: G++-LXDE
- Compiler: GCC-LXDE
- Debugger: GDB-LXDE
- Qt version: Qt 5.9.4 (LXDE)
- Qt mkspec: /usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++
Now one can create a new project using the new Kit. Qt Creator automatically configures build configurations for the cross compiling Kit.
To make sure that the binaries get deployed to the root home folder, add the following to your .pro
file:
target.path = /home/root
INSTALLS += target
If you have an existing project, you can configure Build & Run Configurations under the Project tab on the left side. Go to Add Kit, we can now use the newly created Kit LXDE.
Boot to Qt for Embedded Linux
Boot to Qt for Embedded Linux is not maintained nor supported by Toradex. You can post your question in the Qt Forum, or contact The Qt Company support if using a commercial license.
Build and Deploy the Target Image
For Qt 5, one can install a Boot to Qt evaluation image directly from Toradex Easy Installer. Read the article Partner Demo Image - Qt for Device Creation (Boot to Qt) to learn more.
To build a custom Boot to Qt image, it is necessary to setup an environment on your host PC to build images with the Yocto Project-based on Toradex BSP and Boot to Qt for embedded Linux.
Please refer to Build Your Own Embedded Linux Image article to solve the dependencies associated to the environment and complete this setup according to your host operating system.
Qt 4.8
this section is limited up to the BSP 2.8. Qt 4 is not integrated with BSP 3 onwards, nor instructions on how to do it are provided.
Install Qt Creator
Using Ubuntu
Current long-term release (Ubuntu 18.04) provides Qt Creator 4.5.2, which is sufficient recent for this how-to.
$ sudo apt install qt4-default qtcreator
Using Fedora
$ sudo dnf install qt4 qtcreator
Build and Deploy the Target Image
On the target module, you will need the Qt runtime environment installed. Therefore a new image with the Qt run-time libraries to allow executing Qt applications on the target is required. This step is mandatory!
To build a Qt 4.8 enabled image, it is necessary to set up an environment on your host PC to build images with Yocto Project based on the OpenEmbedded layers and Toradex BSP. Please refer to the OpenEmbedded (core) article to solve the dependencies associated with the environment and complete this setup according to your host operating system.
There are two target images with Qt 4.8 packages available
- angstrom-qt-x11-image : for Qt X11 image (recommended for Tegra and i.MX6 based modules)
- qt4e-demo-image: for Qt Embedded image (recommended for VFxx)
To build them, run
[build] $ bitbake -k angstrom-qt-x11-image
[build] $ bitbake -k qt4e-demo-image
Build the SDK for development
See also Linux SDKs
In order to compile the required libraries, a full OpenEmbedded build environment need to be in place at first (see the Build and Deploy the Target Image for Qt).
We need to have a full Qt toolchain, which provides beside cross GCC and GDB also the Qt headers to include and libraries to link against.
The Qt 4.8 Embedded is still useful for devices without any graphical acceleration or with drivers providing this also to users relying on the frame buffer device. With the modules based on T20/T30 the drivers for hardware-accelerated 3D and video decoding are only available for an X11 system, so you probably want to use Qt on X11.
Install the SDK
Install the Qt toolchain on your development computer (replace x86_64 with i686 if you use a 32-bit machine):
[build] $ cd ../deploy/sdk/
[sdk] $ ./deploy/sdk/angstrom-glibc-x86_64-armv7at2hf-vfp-neon-toolchain-qte-v2014.12.sh
Configure Qt Creator
Before starting Qt Creator, we have to export some build environment variables. Qt uses special configuration files to describe the built environment called mkspecs (they specify which compiler, linker, or other tools to use). However, this configuration files still need to know where the compiler (or cross-compiler in our case) is located. The SDK created a script that does all the hard work.
Using the SDK built with OpenEmbedded layers, source the script as follows:
. /usr/local/oecore-x86_64/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi
It is required to source the script to export the environment variables every time in the same terminal session you run Qt Creator
The environment variable OE_QMAKE_CXX should then show something along this line:
$ echo $OE_QMAKE_CXX
arm-angstrom-linux-gnueabi-g++ -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/usr/local/oecore-x86_64/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi
Now, start Qt Creator in the shell where you sourced the script.
qtcreator
Add the Target Device
Go to Tools → Options. In the left panel, click on Devices and add a new device representing the target Colibri Module:
- Press Add and choose Generic Linux Device
- Specifiy a name (e.g. Colibri VF61)
- Fill in the device's IP address
- Authentication on our modules by default: Password, User ''root'', empty password
Add Kit
In the left panel, click on Build & Run and configure in the following tabs:
- Qt Versions:
- Press Add
- Choose /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/qmake2
- Fill in a name
- Compilers:
- Press Add => Gcc
- Name: GCC (Qt Embedded)
- Compiler path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-g++
- ABI (should be detected automatically): arm-linux-generic-elf-32bit
- Debuggers:
- Press Add
- Name: GDB (Qt Embedded)
- Path: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/arm-angstrom-linux-gnueabi/arm-angstrom-linux-gnueabi-gdb
- Kit
- Press Add
- Name: Toradex Qt Embedded
- Device: Colibri VF61
- Sysroot: /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-neon-angstrom-linux-gnueabi
- Compiler: GCC (Qt Embedded)
- Debugger: GDB (Qt Embedded)
- Qt version: Qt 4.8.6 (Toradex BSP Qt Embedded)
- Qt mkspec: leave empty
Now one can create a new project using the new Kit. Qt Creator automatically configures build configurations for the cross-compiling Kit.
To make sure that the binaries get deployed to the root home folder, add the following to your .pro
file:
target.path = /home/root
INSTALLS += target
If you have an existing project, you can configure Build & Run Configurations under the Project tab on the left side. Go to Add Kit, we can now use the newly created Kit Toradex Qt Embedded.
When using Qt Embedded, you may want to switch to the "Run" configuration and add the argument "-qws" to the binary as standalone (instead of using the Qt for Embedded Linux server).