Search by Tags

How to set up Qt Creator to cross compile for embedded Linux

 
Applicable for

Compare with Revision




Subscribe for this article updates

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.

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 or get in contact with Qt.

You are able to purchase your Qt runtime license directly from Toradex. Please contact your local Toradex office.

Note: Install the Qt for Device Creation Image for the target modules Apalis iMX6, Colibri iMX6 and Colibri iMX7 using the Toradex Easy Installer.


  • Qt Creator

    Qt Creator IDE

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, desktop. One can install Qt Creator from its installer or from your distribution repository.

To install Qt Creator from its installer, download it according to the chosen license.

Run the installer:

$ ./qt-unified-linux-x64-3.0.5-online.run

Note: 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.


  • Toradex Computer on Module: Boot to Qt component selection (click to enlarge)

    Installing Qt for Device Creation (click to enlarge)

For further information about Qt for Device Creation, refer to Partner Demo Image - Qt for Device Creation.

Current long-term release (Ubuntu 18.04) provide Qt Creator 4.5.2, which is sufficient recent for this how to.

sudo apt install build-essential
sudo apt install qtcreator qt5-doc qt5-doc-html qtbase5-doc-html qtbase5-examples

Visit 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:

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 Qt 5.11 enabled image directly from Toradex Easy Installer.

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!

With the commercial license one can enable Qt For Device Creation which one of its key features is providing a pre-built Boot to Qt image. 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 ToolsFlash Boot to Qt device.

Build the SDK for development ​

Note: See also Linux SDKs

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.

With the commercial license one can enable Qt For Device Creation which automatically provides the toolchains for the installed components of the supported devices .

Install the SDK ​

See section above.

Configure Qt Creator ​

Before starting Qt Creator, we have to export some build environment variables. Qt uses special configuration files to describe the build 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 which does all the hard work.

Using the commercial license, the compilation kits for the supported modules are configured out-of-the-box, but it is necessary to configure a target Device.

Go to ToolsOptions and select Devices.

Add a target device and select the Boot2Qt Device.


Fill in with your device name and IP address:


Add the configured device in the auto detected kit.


  • Add Boot2Qt Device to auto detected SDK

    Add Boot2Qt Device to auto detected SDK

Open an existing project or one of the extensive list of Qt examples and enable this kit:


Build with OpenEmbedded Layers

Build and Deploy the Target Image ​​

For Qt 5, one can install a Qt 5.11 enabled image directly from Toradex Easy Installer. 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 an image with Qt5, it is necessary to setup an environment on your host PC to build images with the Yocto Project based on Toradex BSP and the OpenEmbedded layers.

Please refer to the OpenEmbedded (core) article to solve the dependencies associated to the environment and complete this setup according to your host operating system.

Once the setup is done using Toradex BSP 2.7 or newer, one can verify Qt5 layer (meta-qt5) already included in the layers configuration file located at "oe-core/build/conf/bblayers.conf".

bblayers.conf
${TOPDIR}/../layers/meta-openembedded/meta-networking \ ${TOPDIR}/../layers/meta-openembedded/meta-multimedia \ ${TOPDIR}/../layers/meta-lxde \ ${TOPDIR}/../layers/meta-browser \ ${TOPDIR}/../layers/meta-qt5 \
Legacy information about including meta-qt5 layer

One can build the following image target that contains all Qt5 Packages:

  • angstrom-qt5-x11-image: for Qt 5 X11 image without desktop
[build] $ bitbake -k angstrom-qt5-x11-image
Add Qt5 packages to other image targets

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 the SDK for development ​​

Note: 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).

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 OpenEmbedded target providing such a toolchain:

  • meta-toolchain-qt5: For Qt 5, create applications for X-Server or framebuffer with EGLFS without X-Server

To build it, run:

[build] $ bitbake -k meta-toolchain-qt5

The toolchain will be located at "/oe-core/deploy/sdk".

Install the SDK ​​

Install the Qt toolchain on your development computer (replace x86_64 with i686 if you use a 32-bit machine):

[build] $ ../deploy/sdk/angstrom-glibc-x86_64-armv7at2hf-neon-v2016.12-toolchain.sh

Starting qmake should succeed now:

$ /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/qt5/qmake
Usage: /usr/local/oecore-x86_64/sysroots/x86_64-angstromsdk-linux/usr/bin/qt5/qmake [mode] [options] [files]
...

Configure Qt Creator ​​

Before starting Qt Creator, we have to export some build environment variables. Qt uses special configuration files to describe the build 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 which 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

Warning: 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

Note: It is recommended to source the script that exports the environment variables in qtcreator.sh script.

Add the Target Device ​​

Go to ToolsOptions. 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

  • Qt Creator - Devices

    Qt Creator - Devices

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/qt5/qmake
    • Fill in a name

  • Qt Creator - Qt Versions

    Qt Creator - Qt Versions

  • Compilers:
    • Press AddGccC++
    • 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

  • Qt Creator - Compiler

    Qt Creator - Compilers

  • Press AddGccC
  • 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

  • Qt Creator - Compilers

    Qt Creator - Compilers

  • 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

  • Qt Creator - Debugger

    Qt Creator - Debugger

  • 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++

  • Qt Creator -  Kit

    Qt Creator - Kit

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:

*.pro
target.path = /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

Warning: 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 Qt 5.11 enabled image directly from Toradex Easy Installer. 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 an image with Qt5, 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.

After solving the dependencies indicated, it is necessary to download the repositories on your host machine to build Boot to Qt for embedded Linux.

$ mkdir b2qt
$ cd b2qt
$ git clone -b pyro git://code.qt.io/yocto/meta-boot2qt.git
$ cd meta-boot2qt

In this step, one can export the environment variables and set the target device. To check available device configurations, run:

[meta-boot2qt]$ ./b2qt-init-build-env list-devices

This how to uses Apalis iMX8 as the target device.

[meta-boot2qt] $ ./b2qt-init-build-env init --device apalis-imx8
[meta-boot2qt] $ export MACHINE=apalis-imx8
[meta-boot2qt] $ source ./setup-environment.sh
[build-apalis-imx8] $ 

To build the image, run:

[build-apalis-imx8] $  bitbake b2qt-embedded-qt5-image

This can take several hours. When the build finishes, the image files will be located at "/b2qt/meta-boot2qt/build-apalis-imx8/tmp/deploy/images/apalis-imx8".

Note: For more information concerning how to install your newly built image onto the target, refer to Toradex Easy Installer. If your module is not supported by Toradex Easy Installer, have a look at one of the following articles.

Build the SDK for development ​​​

Note: 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 Boot to Qt target providing such toolchain is:

  • meta-toolchain-b2qt-embedded-qt5-sdk

To build it, run:

[build-apalis-imx8] $  bitbake b2qt-embedded-qt5-image

The toolchain will be located at "/b2qt/meta-boot2qt/build-apalis-imx8/tmp/deploy/sdk".

Install the SDK ​​​

Install the Qt toolchain on your development computer (replace x86_64 with i686 if you use a 32-bit machine):

[build-apalis-imx8] $ cd tmp/deploy/sdk
[sdk] $ ls b2qt-x86_64-meta-toolchain-b2qt-embedded-qt5-sdk-colibri-imx6.sh
b2qt-x86_64-meta-toolchain-b2qt-embedded-qt5-sdk-colibri-imx6.sh

Starting qmake should succeed now:

$ /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/qmake 
Usage: /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/qmake [mode] [options] [files]
...

Configure Qt Creator ​​​

Before starting Qt Creator, we have to export some build environment variables. Qt uses special configuration files to describe the build 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 which does all the hard work.

Using the Boot to Qt Embedded Linux SDK, source the script to export the environment variables as follows:

. /opt/b2qt/2.3.4/environment-setup-cortexa7hf-neon-poky-linux-gnueabi

Warning: 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-poky-linux-gnueabi-g++ -march=armv7ve -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/b2qt/2.3.4/sysroots/cortexa7hf-neon-poky-linux-gnueabi

Now, start Qt Creator in the shell where you sourced the script.

Using QtCreator 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

Note: It is recommended to source the script that exports the environment variables in qtcreator.sh script.

Add the Target Device ​​​

Go to ToolsOptions. 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

  • Qt Creator - Devices

    Qt Creator - Devices

Add Kit ​​​

In the left panel, click on Build & Run and configure in the following tabs:

  • Qt Versions:
    • Press Add
    • Choose /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/qmake
    • Fill in a name

  • Qt Creator - Qt Version

    Qt Creator - Qt Version

  • Compilers:
    • Press AddGccC++
    • Name: G++-B2Qt
    • Compiler path: /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++
    • ABI (should be detected automatically): arm-linux-generic-elf-32bit

  • Qt Creator - Compilers

    Qt Creator - Compilers

  • Press AddGccC
  • Name: GCC-B2Qt
  • Compiler path: /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
  • ABI (should be detected automatically): arm-linux-generic-elf-32bit

  • Qt Creator - Compilers

    Qt Creator - Compilers

  • Debuggers:
    • Press Add
    • Name: GDB-B2Qt
    • Path: /opt/b2qt/2.3.4/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb

  • Qt Creator - Debugger

    Qt Creator - Debugger

  • Kit
    • Press Add
    • Name: B2Qt
    • Device: Apalis iMX8
    • Sysroot: /opt/b2qt/2.3.4/sysroots/cortexa7hf-neon-poky-linux-gnueabi/
    • Compiler: G++-B2Qt
    • Compiler: GCC-B2Qt
    • Debugger: GDB-B2Qt
    • Qt version: Qt 5.11
    • Qt mkspec: /opt/b2qt/2.3.4/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/lib/mkspecs/linux-oe-g++

  • Qt Creator - Kits

    Qt Creator - Kits

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:

*.pro
target.path = /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 B2Qt.

Qt 4.8

Install Qt Creator​

Using Ubuntu

Current long-term release (Ubuntu 18.04) provide 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 setup 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 to 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 ​​​​

Note: 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.

There are two OpenEmbedded targets providing such a toolchain:

  • meta-toolchain-qt: Qt 4.8 X11, create applications for X-Server
  • meta-toolchain-qte: Qt 4.8 Embedded, without X-Server directly on framebuffer (using QWT)

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] $ ../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 build 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 which 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

Warning: It is required to source the script to export the environment variables everytime 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 ToolsOptions. 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

  • Qt Creator - Devices

    Qt Creator - Devices

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

  • Qt Creator - Qt Versions

    Qt Creator - Qt Versions

  • 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

  • Qt Creator - Compilers

    Qt Creator - Compilers

  • 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

  • Qt Creator - Debuggers

    Qt Creator - Debuggers

  • 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

  • Qt Creator - Kits

    Qt Creator - Kits

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:

*.pro
target.path = /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.

Note: When using Qt Embedded, you may want to switch to the "Run" configuration and add the argument "-qws" to the binary as standalone (instead using the Qt for Embedded Linux server).

See also