Qt6 on QNX: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Created page with "= Building Qt6 for QNX 7.1 = This page covers the process of building and deploying Qt6 for QNX 7.1. === Preparing the SDP === In order to get the full-set of Qt features m...")
 
m (Corrected the toolchain file location.)
 
(9 intermediate revisions by one other user not shown)
Line 1: Line 1:
= Building Qt6 for QNX 7.1 =
This page covers the process of building and deploying Qt6 for QNX 7.1.


This page covers the process of building and deploying Qt6 for QNX 7.1.
=== QNX SDP ===
 
In order to build applications for a QNX target, one needs to download and install the QNX SDP, which contains the QNX toolchain for ''x86_64'', ''armle-v7'' and ''aarch64le'', as well as a collection of tools to aid the creation of QNX system images for select targets and virtual machines. A ''myQNX'' account and a valid license are required in order to obtain the QNX SDP. You can create a new account [https://www.qnx.com/account/login.html#showcreate here].
 
Once an account has been created, you'll need to download the [https://www.qnx.com/download/group.html?programid=29178 QNX Software Center], from which the QNX SDP can be downloaded.


=== Preparing the SDP ===
==== Installing the SDP ====


In order to get the full-set of Qt features make sure the following packages are installed for your target (x64 or arm)
From within QNX Software Center, select the following packages:


* QNX Software Development Platform 7.1 [com.qnx.qnx710] - this may appear as a baseline inside the QNX Software Center
* QNX Software Development Platform 7.1 [com.qnx.qnx710] - this may appear as a baseline inside the QNX Software Center
Line 12: Line 16:
* QNX SDP 7.1 Time Zone Database [com.qnx.qnx710.osr.zoneinfo]
* QNX SDP 7.1 Time Zone Database [com.qnx.qnx710.osr.zoneinfo]
* QNX SDP 7.1 Image Codecs [com.qnx.qnx710.target.screen.img_codecs]
* QNX SDP 7.1 Image Codecs [com.qnx.qnx710.target.screen.img_codecs]
==== Using the SDP ====
The QNX SDP ships with a GCC based compiler called QCC. Before this compiler can be used, we need to setup the environment. This is done by sourcing <code>qnx710/qnxsdp-env.sh</code> on Linux or invoking <code>qnx710/qnxsdp-env.bat</code> on Windows. These scripts set a few important environment variable, including:
* '''QNX_HOST''' - the base path for the QNX tools and compiler for the host operating system
* '''QNX_TARGET''' - the base path for the source, binary and configuration files that are used (deployed) to the target QNX system
Once the environment has been setup, you can invoke the QNX compiler driver to produce a binary (qcc for C, q++ for C++), specifying the target architecture using the -V command line switch, for instance:
qcc -Vgcc_ntoaarch64le foo foo.c # ''builds an aarch64le binary''
q++ -Vgcc ntox86_64 bar bar.cpp  # ''builds a x86_64 binary (the default when -V is omitted)''
'''IMPORTANT INFORMATION:''' QCC does not handle paths containing whitespace well. It's best to avoid them altogether.
=== Building Qt6/QNX on Linux Hosts ===
The process to cross-compile Qt for QNX is divided in two parts. First, we need to build and install Qt6 for Linux. This Qt installation is then used to support the build of Qt6 binaries targeting QNX.
==== Clone and initialize qt5.git ====
$ git clone git://code.qt.io/qt/qt5.git
$ cd qt5
$ perl init-repository
==== Create a build directory, configure, build and install ====
$ mkdir build_host
$ cd build_host
$../configure -prefix $HOME/dev/Qt6_host -nomake tests
$ cmake --build . --parallel
$ cmake --install .
Assuming everything went well, we can now build Qt for QNX. In the example below, we will build for aarch64le targets. You can obtain the relevant toolchain files in <code>https://code.qt.io/cgit/qt/qt5.git/tree/coin/provisioning/common/shared/cmake_toolchain_files</code>.
$ mkdir build_qnx
$ cd build_qnx
$ source <path_to_qnx_sdp>/qnx710/qnxsdp-env.sh
$ cmake -DQT_HOST_PATH=$HOME/dev/Qt6_host \ # this is the path of the host Qt we've just built
  -DCMAKE_TOOLCHAIN_FILE=../coin/provisioning/common/linux/cmake_toolchain_files/qnx-toolchain-aarch64le.cmake \
  -G Ninja \
  -DCMAKE_STAGING_PREFIX=$HOME/dev/Qt6_qnx \ # the prefix where Qt will be installed on the host
  -DCMAKE_INSTALL_PREFIX=/qt \ # the prefix where Qt will be installed on the target, used to populate RPATH on binaries built against this Qt version
  ..
$ cmake --build . --parallel
$ cmake --install .
=== Building Qt6/QNX on Windows Hosts ===
Building Qt6/QNX on Windows hosts is analogous to the process to build it on Linux hosts, except that a little more is required to prepare the environment.
==== Setting up the environment ====
Apart from Visual Studio, it's important that the other dependencies are installed to paths that do not contain spaces. As mentioned before, the QNX tools have issues dealing with paths containing whitespace (e.g. it doesn't know how to properly escape the path strings when passing them to cc1plus). The safest way is to simply install Perl, Python, Ninja and CMake directly under C:\
# Install [https://visualstudio.microsoft.com/vs/ Microsoft Visual Studio 2022] (Community Edition will do just fine)
# Install [https://strawberryperl.com/ Strawberry Perl] - '''DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH'''
# Install [https://www.python.org/downloads/windows/ Python for Windows] - '''DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH'''
# Install [https://cmake.org/download/ CMake >= 3.22] - it's recommended to simply use the Windows x64 ZIP to prevent the installer from messing with the system, also '''DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH'''
# Install [https://github.com/ninja-build/ninja/releases Ninja]
==== Clone and initialize qt5.git ====
C:\Users\John> set PATH=%PATH%;c:\Strawberry\perl\bin
C:\Users\John> git clone git://code.qt.io/qt/qt5.git
C:\Users\John> cd qt5
C:\Users\John\qt5> perl init-repository
==== The host Qt needs to be built from a Visual Studio 2022 64-bit hosted developer command prompt. You can launch it from the following Start menu shortcut: ====
[[File:Image2022-3-1 17-47-24.png|frameless]]
==== Create a build directory, configure, build and install ====
C:\Users\John\qt5> set PATH=%PATH%;C:\CMake\bin;C:\Strawberry\perl\bin;C:\Python;C:\Ninja
C:\Users\John\qt5> mkdir build_host
C:\Users\John\qt5> cd build_host
C:\Users\John\qt5>..\configure -prefix C:\Qt6_host -nomake tests
C:\Users\John\qt5> cmake --build . --parallel
C:\Users\John\qt5> cmake --install .
''You can now close the Visual Studio command prompt.''
We can now go ahead and build Qt for the QNX targets. This must be done from a regular command prompt.
[[File:Image2022-3-1 17-46-53.png|frameless]]
'''IMPORTANT INFORMATION:''' The order in which the <code>PATH</code> variable is being set below does matter.
==== Create a build directory (from the qt5 dir),  source the QNX environment, configure, build and install ====
C:\Users\John\qt5> mkdir build_qnx
C:\Users\John\qt5> cd build_qnx
C:\Users\John\qt5> set PATH=C:\CMake\bin;%PATH% # add cmake to the front of the path
C:\Users\John\qt5> <path_to_qnx_sdp>\qnx710\qnxsdp-env.bat
C:\Users\John\qt5> set PATH=%PATH%;C:\Strawberry\perl\bin;C:\Python;C:\Ninja
C:\Users\John\qt5> cmake -DQT_HOST_PATH=c:\Qt6_host -DCMAKE_TOOLCHAIN_FILE=C:\Users\John\qt5\coin\provisioning\common\linux\cmake_toolchain_files\qnx-toolchain-aarch64le.cmake -G "Ninja" -DCMAKE_LIBRARY_PATH=<path_to_qnx_sdp>\target\qnx7\aarch64le\lib;<path_to_qnx_sdp>\target\qnx7\aarch64le\usr\lib -DBUILD_WITH_PCH=OFF -DCMAKE_STAGING_PREFIX=c:\Qt6_qnx -DCMAKE_INSTALL_PREFIX=/qt ..
C:\Users\John\qt5> cmake --build . --parallel
C:\Users\John\qt5> cmake --install .
'''IMPORTANT INFORMATION:''' PCH are explicitly disabled as the QNX compiler crashes when building with PCH enabled on Windows.

Latest revision as of 07:59, 13 August 2024

This page covers the process of building and deploying Qt6 for QNX 7.1.

QNX SDP

In order to build applications for a QNX target, one needs to download and install the QNX SDP, which contains the QNX toolchain for x86_64, armle-v7 and aarch64le, as well as a collection of tools to aid the creation of QNX system images for select targets and virtual machines. A myQNX account and a valid license are required in order to obtain the QNX SDP. You can create a new account here.

Once an account has been created, you'll need to download the QNX Software Center, from which the QNX SDP can be downloaded.

Installing the SDP

From within QNX Software Center, select the following packages:

  • QNX Software Development Platform 7.1 [com.qnx.qnx710] - this may appear as a baseline inside the QNX Software Center
  • QNX SDP 7.1 DejaVu Fonts [com.qnx.qnx710.target.screen.fonts.dejavu]
  • QNX SDP 7.1 Font Engine [com.qnx.qnx710.target.screen.fonts.engine]
  • QNX SDP 7.1 Time Zone Database [com.qnx.qnx710.osr.zoneinfo]
  • QNX SDP 7.1 Image Codecs [com.qnx.qnx710.target.screen.img_codecs]

Using the SDP

The QNX SDP ships with a GCC based compiler called QCC. Before this compiler can be used, we need to setup the environment. This is done by sourcing

qnx710/qnxsdp-env.sh

on Linux or invoking

qnx710/qnxsdp-env.bat

on Windows. These scripts set a few important environment variable, including:

  • QNX_HOST - the base path for the QNX tools and compiler for the host operating system
  • QNX_TARGET - the base path for the source, binary and configuration files that are used (deployed) to the target QNX system

Once the environment has been setup, you can invoke the QNX compiler driver to produce a binary (qcc for C, q++ for C++), specifying the target architecture using the -V command line switch, for instance:

qcc -Vgcc_ntoaarch64le foo foo.c # builds an aarch64le binary
q++ -Vgcc ntox86_64 bar bar.cpp  # builds a x86_64 binary (the default when -V is omitted)

IMPORTANT INFORMATION: QCC does not handle paths containing whitespace well. It's best to avoid them altogether.

Building Qt6/QNX on Linux Hosts

The process to cross-compile Qt for QNX is divided in two parts. First, we need to build and install Qt6 for Linux. This Qt installation is then used to support the build of Qt6 binaries targeting QNX.

Clone and initialize qt5.git

$ git clone git://code.qt.io/qt/qt5.git
$ cd qt5
$ perl init-repository

Create a build directory, configure, build and install

$ mkdir build_host
$ cd build_host
$../configure -prefix $HOME/dev/Qt6_host -nomake tests
$ cmake --build . --parallel
$ cmake --install .

Assuming everything went well, we can now build Qt for QNX. In the example below, we will build for aarch64le targets. You can obtain the relevant toolchain files in

https://code.qt.io/cgit/qt/qt5.git/tree/coin/provisioning/common/shared/cmake_toolchain_files

.

$ mkdir build_qnx
$ cd build_qnx
$ source <path_to_qnx_sdp>/qnx710/qnxsdp-env.sh
$ cmake -DQT_HOST_PATH=$HOME/dev/Qt6_host \ # this is the path of the host Qt we've just built
  -DCMAKE_TOOLCHAIN_FILE=../coin/provisioning/common/linux/cmake_toolchain_files/qnx-toolchain-aarch64le.cmake \
  -G Ninja \
  -DCMAKE_STAGING_PREFIX=$HOME/dev/Qt6_qnx \ # the prefix where Qt will be installed on the host
  -DCMAKE_INSTALL_PREFIX=/qt \ # the prefix where Qt will be installed on the target, used to populate RPATH on binaries built against this Qt version
  ..
$ cmake --build . --parallel
$ cmake --install .


Building Qt6/QNX on Windows Hosts

Building Qt6/QNX on Windows hosts is analogous to the process to build it on Linux hosts, except that a little more is required to prepare the environment.

Setting up the environment

Apart from Visual Studio, it's important that the other dependencies are installed to paths that do not contain spaces. As mentioned before, the QNX tools have issues dealing with paths containing whitespace (e.g. it doesn't know how to properly escape the path strings when passing them to cc1plus). The safest way is to simply install Perl, Python, Ninja and CMake directly under C:\

  1. Install Microsoft Visual Studio 2022 (Community Edition will do just fine)
  2. Install Strawberry Perl - DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH
  3. Install Python for Windows - DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH
  4. Install CMake >= 3.22 - it's recommended to simply use the Windows x64 ZIP to prevent the installer from messing with the system, also DO NOT AUTOMATICALLY ADD IT TO THE SYSTEM PATH
  5. Install Ninja

Clone and initialize qt5.git

C:\Users\John> set PATH=%PATH%;c:\Strawberry\perl\bin
C:\Users\John> git clone git://code.qt.io/qt/qt5.git
C:\Users\John> cd qt5
C:\Users\John\qt5> perl init-repository

The host Qt needs to be built from a Visual Studio 2022 64-bit hosted developer command prompt. You can launch it from the following Start menu shortcut:

Image2022-3-1 17-47-24.png

Create a build directory, configure, build and install

C:\Users\John\qt5> set PATH=%PATH%;C:\CMake\bin;C:\Strawberry\perl\bin;C:\Python;C:\Ninja
C:\Users\John\qt5> mkdir build_host
C:\Users\John\qt5> cd build_host
C:\Users\John\qt5>..\configure -prefix C:\Qt6_host -nomake tests
C:\Users\John\qt5> cmake --build . --parallel
C:\Users\John\qt5> cmake --install .

You can now close the Visual Studio command prompt.

We can now go ahead and build Qt for the QNX targets. This must be done from a regular command prompt.

Image2022-3-1 17-46-53.png

IMPORTANT INFORMATION: The order in which the

PATH

variable is being set below does matter.

Create a build directory (from the qt5 dir), source the QNX environment, configure, build and install

C:\Users\John\qt5> mkdir build_qnx
C:\Users\John\qt5> cd build_qnx
C:\Users\John\qt5> set PATH=C:\CMake\bin;%PATH% # add cmake to the front of the path
C:\Users\John\qt5> <path_to_qnx_sdp>\qnx710\qnxsdp-env.bat
C:\Users\John\qt5> set PATH=%PATH%;C:\Strawberry\perl\bin;C:\Python;C:\Ninja
C:\Users\John\qt5> cmake -DQT_HOST_PATH=c:\Qt6_host -DCMAKE_TOOLCHAIN_FILE=C:\Users\John\qt5\coin\provisioning\common\linux\cmake_toolchain_files\qnx-toolchain-aarch64le.cmake -G "Ninja" -DCMAKE_LIBRARY_PATH=<path_to_qnx_sdp>\target\qnx7\aarch64le\lib;<path_to_qnx_sdp>\target\qnx7\aarch64le\usr\lib -DBUILD_WITH_PCH=OFF -DCMAKE_STAGING_PREFIX=c:\Qt6_qnx -DCMAKE_INSTALL_PREFIX=/qt ..
C:\Users\John\qt5> cmake --build . --parallel
C:\Users\John\qt5> cmake --install .

IMPORTANT INFORMATION: PCH are explicitly disabled as the QNX compiler crashes when building with PCH enabled on Windows.