Note:
📌 The Qt demonstration project was written using the Windows version of Qt5.12.10. The virtual machine is running Ubuntu 18.04.6.
一、Ubuntu Porting
We use a cross-compilation approach in the virtual machine to compile the Qt source code and project, producing a program that can run on the development board.
1. Install the Cross Compiler (GNU)
Cross compiler download link: https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/
Copy the downloaded cross-compilation tool gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz to the directory where you want to install it. Here, we choose the /opt folder. After copying, run the following command in the /opt directory to extract it:
sudo tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar -C /opt/
After extraction, a folder named gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu will be created. The name of this folder is quite long, so we will rename it to gcc-aarch64-linux-gnu:
sudo mv gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu gcc-aarch64-linux-gnu
Add the /opt/gcc-aarch64-linux-gnu/bin directory to the environment variables:
sudo gedit /etc/profile
At the end of the file, add the following content:
export PATH="/opt/gcc-aarch64-linux-gnu/bin:$PATH"
Then run the command to make the environment variables take effect:
source /etc/profile
Reboot the system:
reboot
After rebooting, run the following command to check if the environment variables have been applied successfully:
aarch64-linux-gnu-gcc -v
If you see the following situation, it means the installation was successful.
2. Cross-compiling the Qt Library
WARNING
📌 If the cross-compilation of the Qt library keeps failing, you can directly download the pre-cross-compiled Qt5.12.10 library from the Download Link (Baidu Netdisk) from Download Center
.
📌 Download Center (click to jump)
📌 在 Download Center
->Baidu Netdisk Resource Content
-> Chapter 11. FAQs
-> Qt5.12.10-arm【RK3566】
-> qt5.12.10.tar.gz
We need to download the Qt5.12.10 source code and use the cross-compiler to compile the Qt source, transferring the support libraries to the development board so that the Qt programs can run. Download link: https://download.qt.io/archive/qt/5.12/5.12.10/single/
The md5sums.txt file below contains the checksum. We recommend verifying it after downloading and transferring it to the virtual machine to ensure there were no errors during the download.
Copy the downloaded compressed package to the /opt directory and extract it:
tar -xvf qt-everywhere-src-5.12.10.tar.xz
After extraction, you will have the folder /opt/qt-everywhere-src-5.12.10. Next, we need to edit the qmake configuration file:
sudo gedit /opt/qt-everywhere-src-5.12.10/qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf
Modify the file to the following:
#
# qmake configuration for building with aarch64-linux-gnu-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = aarch64-linux-gnu-gcc
QMAKE_CXX = aarch64-linux-gnu-g++
QMAKE_LINK = aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB = aarch64-linux-gnu-g++
# modifications to linux.conf
QMAKE_AR = aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY = aarch64-linux-gnu-objcopy
QMAKE_NM = aarch64-linux-gnu-nm -P
QMAKE_STRIP = aarch64-linux-gnu-strip
load(qt_config)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
The key lines to add are:
QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts
QT_QPA_DEFAULT_PLATFORM = linuxfb:
This line sets the default platform plugin for Qt Quick/QML applications.
linuxfb
stands for Linux Framebuffer, a method used to directly control display devices in embedded systems. Setting this tolinuxfb
means the Qt application will use Linux Framebuffer as the default graphics platform, which is common in some embedded systems.QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts:
This line sets the compilation flags for C code when building in Release mode.
-O2
enables optimization level 2, which applies more optimizations to improve code performance.-march=armv8-a
specifies that the generated code is for ARMv8-A architecture, which supports a 64-bit instruction set common in modern ARM processors.QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts:
This line sets the compilation flags for C++ code in Release mode, similarly applying the same optimizations and target architecture.
Navigate to the Qt library folder:
cd /opt/qt-everywhere-src-5.12.10/
Create an autoConfig.sh script:
sudo gedit autoConfig.sh
Enter the following content in the script:
#!/bin/sh
./configure \
-prefix /opt/qt5.12.10-arm \
-confirm-license \
-opensource \
-release \
-make libs \
-xplatform linux-aarch64-gnu-g++ \
-pch \
-qt-libjpeg \
-qt-libpng \
-qt-zlib \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-dbus \
-no-separate-debug-info \
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-prefix /opt/qt5.12.10-arm
: Specifies the Qt installation path as/opt/qt5.12.10-arm
. After compilation, the Qt libraries and tools will be installed in this directory.-confirm-license
: Confirms the acceptance of the Qt license agreement.-opensource
: Compiles Qt under the open-source license.-release
: Compiles Qt as a release version, rather than a debug version.-make libs
: Compiles only the Qt libraries, without compiling example programs.-xplatform linux-aarch64-gnu-g++
: Specifies the target platform as Linux and compiles using theaarch64
architecture.gnu-g++
means using the GNU toolchain.-pch
: Enables precompiled headers to speed up the compilation process.-qt-libjpeg
,-qt-libpng
,-qt-zlib
: Specifies using the system-installed libjpeg, libpng, and zlib libraries during Qt compilation.-no-opengl
: Does not compile the OpenGL module of Qt.-no-sse2
: Disables the SSE2 instruction set optimization.-no-openssl
: Does not compile the OpenSSL module of Qt.-no-cups
: Does not compile the CUPS module of Qt (for printing support).-no-glib
: Does not compile the GLib module of Qt.-no-dbus
: Does not compile the D-Bus module of Qt.-no-separate-debug-info
: Does not generate separate debug information files.
Grant execution permissions to the .sh script:
sudo chmod 777 autoConfig.sh
Now, run the autoConfig.sh script to automatically generate the Makefile:
./autoConfig.sh
After running, you should see the following output:
Next, we use the make command to begin the compilation (this may take some time):
sudo make -j12
Once the compilation is complete, use the following command to install:
sudo make install
After a while, you should see the installation directory /opt/qt5.12.10-arm in the /opt folder, indicating that the installation was successful.
3. Compile Qt Project Files
Next, copy the project files to the virtual machine for cross-compilation, and you can place them anywhere. First, we need to delete the .user file, as it is a user configuration file for the Windows environment:
Then,use the cd command to enter the project folder directory. Inside, type the following command to create a Makefile using qmake:
Note: This is the cross-compiled Qt library installation directory (qt5.12.10-arm). Use the absolute path of qmake. If you changed the qmake path, make sure to update it to the correct absolute path.
/opt/qt5.12.10-arm/bin/qmake
After running this, you should see a Makefile in the project directory. Now, run the Makefile:
sudo make -j12
Wait a moment, and you will see a runnable program with the same name as the .pro file:
In the image example, the file to be copied to the development board for execution is ClockTop.
4. Deploy Qt Library
Next, copy the qt5.12.10-arm folder to the development board. Qt applications need these libraries to run!
WARNING
📌 If cross-compiling the Qt library keeps failing, you can directly download the Qt5.12.10 libraries that we have successfully cross-compiled from the Download Link (Baidu Netdisk) from Download Center
📌 Download Center (Click here)
📌 在 Download Center
->Baidu Netdisk Resource Content
-> Chapter 11. FAQs
-> Qt5.12.10-arm【RK3566】
-> qt5.12.10.tar.gz
Enter the command in the /opt directory:
Compress the qt5.12.10-arm folder into the qt5.12.10.tar.gz file:
tar -zcvf qt5.12.10.tar.gz qt5.12.10-arm
Next, transfer the qt5.12.10.tar.gz file to the /opt directory of the development board. You can use a USB drive or other transfer tools. This step will not be demonstrated here.
After transferring it to the /opt directory, extract the file:
sudo tar -xvzf qt5.12.10.tar.gz
Then, add the relevant files and configurations required by the Qt program to the environment variables:
sudo vi /etc/profile
At the end of the file, add the following:
export QTEDIR=/opt/qt5.12.10-arm/
export LD_LIBRARY_PATH=/opt/qt5.12.10-arm/lib:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=$QTEDIR/plugins
export QT_QPA_PLATFORM=linuxfb
export QT_QPA_FONTDIR=/usr/share/fonts/truetype/ubuntu
2
3
4
5
These commands are used to set environment variables related to the Qt runtime:
QTEDIR
: This variable specifies the installation directory of Qt. In the previous step, Qt is installed under/opt/qt5.12.10-arm/
.LD_LIBRARY_PATH
: This variable tells the system which directories to search for dynamic link libraries at runtime. The Qt library directory is added to this variable so that the program can link correctly to the Qt libraries.QT_QPA_PLATFORM_PLUGIN_PATH
: This variable specifies the path to the Qt platform plugins. It points to the Qt plugin directory.QT_QPA_PLATFORM
: This variable specifies the platform plugin that Qt will use. It is set tolinuxfb
, meaning Qt will use the Linux Framebuffer as its graphical output.QT_QPA_FONTDIR
: This variable specifies the directory where the Qt font files are located. It is set to the directory containing the font files.By setting these environment variables, you ensure that when running Qt programs, they can correctly find the necessary libraries, plugins, and font files, thus ensuring the program works properly.
Note:
📌 The /usr/share/fonts/truetype/ubuntu path can be changed to another path. If you specified a particular font in the project, you can transfer the .ttf file for that font to the development board and specify it directly.
Finally, reboot the development board to make the environment variables take effect:
reboot
5. Running the Qt Program
We will copy the ClockTop file from the virtual machine to the development board, which can be done using a USB drive or other tools.
The file to be copied to the Taishan board is highlighted in the image below.
Once the copy is complete, we can run the Qt program directly on the Taishan board:
sudo ./ClockTop
2. Buildroot Qt5 Porting
Buildroot is a tool for embedded Linux systems that helps you build a customized Linux system image. Buildroot supports integrating Qt5 into your embedded Linux system and can help you build a root file system that includes Qt5 applications.
1. Compile the SDK
DANGER
📌 Note: Compile the entire SDK first before performing any Buildroot operations.
Reference: Linux System Compilation (Click to Jump 🚀)
Navigate to the SDK directory:
This is my SDK directory.
Enter the following command to select the board configuration and rootfs environment variables for the Taishan board:
./build.sh lunch && export RK_ROOTFS_SYSTEM=buildroot
Then we begin the compilation process (it might take some time depending on your computer's configuration).
Note: Ensure that all necessary software is installed. For more details, refer to the Taishan board documentation on [SDK Compilation]. Run ./build.sh all. The following image indicates the compilation has completed.
2. Load Environment Variables
We need to execute the buildroot/build/envsetup.sh script to load the environment variables, functions, etc., defined in it into the current shell environment.
Note: We are still in the root directory of the Linux SDK and do not need to enter the Buildroot directory.
source buildroot/build/envsetup.sh
Select: 65
3. Adding Qt Support in the menuconfig Menu
n the root directory of the SDK, enter the following command to configure:
make menuconfig
This will take you to the following interface:
- Use the arrow keys ↑↓ to select Target packages
Press Enter to proceed.
- Use the arrow keys ↑↓ to select Graphic libraries and applications (graphic/text)
Press Enter to proceed.
- After entering, use the arrow keys ↑↓ to find Qt5, press y on the keyboard to select it. Once the [] box appears in front, press Enter to proceed.
- Once inside, modify the settings to match the options shown in the image below.
[] Qt5 --->
[] gui module
[] widgets module
[] fontconfig support
[] GIF support
[] JPEG support
[] PNG support
[] syslog support
[] Enable Tslib support
[] qt5serialport
[] qt5virtualkeyboard
(en_GB) language layouts
2
3
4
5
6
7
8
9
10
11
12
- Qt5: Select to compile the Qt5 library.
- gui module: Select to compile the Qt5 GUI module.
- widgets module: Select to compile the Qt5 Widgets module.
- fontconfig support: Fontconfig is a library for configuring and customizing fonts. It provides a unified way to manage the fonts installed on the system. Enabling this option allows Qt5 to use Fontconfig for font management, improving font configuration and rendering.
- GIF support: Enable support for the GIF image format.
- JPEG support: Enable support for the JPEG image format.
- PNG support: Enable support for the PNG image format
- syslog support: Enable system log support.
- Enable Tslib support: Enable support for Tslib, an abstraction library for touchscreen devices.
- qt5serialport: Select to compile the Qt5 serial port communication module.
- qt5serialport: Select to compile the Qt5 serial port communication module.
- qt5virtualkeyboard: Select to compile the Qt5 virtual keyboard module.
- (en_GB) language layouts: Select British English as the default language layout.
- gui module: Select to compile the Qt5 GUI module.
After saving (use the arrow keys to select Save and press Enter), you can select Exit to return to the previous screen.
- Exit menuconfig menu
We can exit the menuconfig menu (back to the command line) by selecting Exit in the main menu as well.
4. Save the Configuration
After saving and exiting the menuconfig menu, enter the following command in the SDK root directory to apply the saved configuration as the default configuration:
make savedefconfig
5. Compile
Start the overall compilation. Since the previous modules have already been compiled, the process will be much faster.
./build.sh all
Note: During the compilation process, modules like Qt5, which were added earlier, will be automatically downloaded.
If you encounter the following errors or if the download is too slow, please download the files directly to your Windows computer and place them in the dl folder under the buildroot directory. (Copy the URL to the browser's search bar) This is caused by the virtual machine's inability to open websites.
Once done, run ./build.sh all
again to continue the compilation. If everything is successful, the following message will appear.
6. Testing
Once the build is complete, you can find in the qt5base-5.15.2 folder in the /buildroot/output/build directory.
Additionally, by searching in the /buildroot/output/rockchip_rk3566/target directory, you can also find Qt-related folders and files, which is an important check!
sudo find * -name "*qt*"
7. Generate the Image
Once everything is in place, enter the following command in the SDK root directory to generate the image:
./mkfirmware.sh
If you only want to burn the rootfs.img image, you can go to the rockdev folder in the SDK root directory and find the rootfs.img to burn it.
To burn the complete image, continue running the following command to generate the full system image (update.img):
./build.sh updateimg
8. Flash the Image
The images we generated are located in the rockdev folder under the SDK directory, which contains all the images. For detailed instructions on burning, please refer to:
9. Compile the Qt Project Files
After burning the image onto the development board, the Qt environment on the board is ready. Now we can start compiling the Qt project.
Use the qmake tool from the buildroot file to compile the Qt project.
The location is: /buildroot/output/rockchip_rk3566/build/qt5base-5.15.2/bin/qmake in the linuxSDK directory.
Next, copy the project files to the virtual machine and perform cross-compilation in any directory.
First, we need to delete the .user file, as it contains Windows environment-specific user configurations:
Then, use the cd command to enter the project folder, and run the following command to create a Makefile using qmake:
sudo /home/lipeng/share/TaiShanPai/linuxSDK/buildroot/output/rockchip_rk3566/build/qt5base-5.15.2/bin/qmake ClockTop.pro
Note: The qmake path here is the absolute path on my computer. You can find it by following a similar structure on your own system—it’s easy to locate. After running qmake, a Makefile will be generated.
Then, run make to generate the executable:
sudo make
Once successful, an executable file will be created in the project folder:
Grant permissions to this file:
sudo chmod 777 ClockTop
10. Run the Qt Program
Copy the ClockTop file from the virtual machine to the development board using a USB drive or other tools.
The file to copy to LCSC Taishan-RK3566-Linux Dev Board is highlighted in the image below.
After copying, you can directly run the Qt program on the LCSC Taishan-RK3566-Linux Dev Board
./ClockTop
or
The
--platform linuxfb
argument tells ClockTop to use the Linux Framebuffer (linuxfb) as the display platform.
./ClockTop --platform linuxfb