Command-line compilation is suitable for CI/CD pipelines or headless server environments, using the same toolchain and sysroot as Qt Creator. This chapter covers three scenarios: bare g++ toolchain verification, CMake cross-compilation, and qmake cross-compilation.
Prerequisites: The SDK is located at
/home/lckfb/TaishanPi-3-Linux, and Buildroot has completed its first build (see Buildroot Qt Build Environment). If you need to deploy compiled binaries to the board, please complete the Communication Channel Configuration first.
Cross-Compilation Toolchain Overview
Toolchain Description
Important: The Buildroot route must use the Buildroot-bundled toolchain
After a full Buildroot build, a GCC 12.4.0 toolchain (prefix aarch64-buildroot-linux-gnu-) is generated under buildroot/output/rockchip_rk3576/host/bin/. Qt 5.15.11 and all libraries in the sysroot are built with this compiler.
The SDK-bundled GCC 10.3.1 (under prebuilts/gcc/, prefix aarch64-rockchip1031-linux-gnu-) is used for compiling the kernel and u-boot, and cannot be used to compile Qt applications — the two have incompatible C++ ABIs (libstdc++ symbol version mismatch).
| Item | Value |
|---|---|
| Compiler path | buildroot/output/rockchip_rk3576/host/bin/ |
| Compiler prefix | aarch64-buildroot-linux-gnu- |
| GCC version | 12.4.0 |
| sysroot | buildroot/output/rockchip_rk3576/host/aarch64-buildroot-linux-gnu/sysroot (staging/ is a symlink to it) |
Configuring PATH
Execute the following each time you open a new terminal:
export PATH=/home/lckfb/TaishanPi-3-Linux/buildroot/output/rockchip_rk3576/host/bin:$PATHVerification:
aarch64-buildroot-linux-gnu-gcc --version
# Expected output contains: aarch64-buildroot-linux-gnu-gcc.br_real (Buildroot -g8c544b52-dirty) 12.4.02
It is not recommended to add this path to
~/.bashrc, as it will conflict with the SDK-bundled toolchain. Manually export it when needed.
Verifying the Toolchain with g++
First, use the simplest program to confirm the toolchain works properly:
// hello.cpp
#include <iostream>
int main() {
std::cout << "Hello from TaishanPi-3M!" << std::endl;
return 0;
}2
3
4
5
6
aarch64-buildroot-linux-gnu-g++ hello.cpp -o hello
file hello
# Expected output: ELF 64-bit LSB executable, ARM aarch64, ...2
3
Seeing ARM aarch64 means the toolchain is working. If the output shows x86-64, the PATH has not taken effect — re-run the export command from the previous section.
CMake Cross-Compilation for Qt Programs
CMake is the recommended build method. Buildroot includes a toolchainfile.cmake, so there is no need to write a toolchain file manually.
Project Structure
tspi-sysmonitor/
├── CMakeLists.txt
├── tspi-sysmonitor.pro
├── main.cpp
├── sysmonitor.h
└── sysmonitor.cpp2
3
4
5
6
For the complete source code, refer to the sample project tspi-sysmonitor.
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(tspi-sysmonitor LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 REQUIRED COMPONENTS Widgets Network)
add_executable(tspi-sysmonitor
main.cpp
sysmonitor.cpp
)
target_link_libraries(tspi-sysmonitor PRIVATE Qt5::Widgets Qt5::Network)2
3
4
5
6
7
8
9
10
11
12
13
14
15
Configuration and Compilation
cd tspi-sysmonitor
mkdir build && cd build
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=/home/lckfb/TaishanPi-3-Linux/buildroot/output/rockchip_rk3576/host/share/buildroot/toolchainfile.cmake \
-DCMAKE_PREFIX_PATH=/home/lckfb/TaishanPi-3-Linux/buildroot/output/rockchip_rk3576/staging/usr/lib/cmake \
-DCMAKE_BUILD_TYPE=Release
make -j$(nproc)2
3
4
5
6
7
Key parameter descriptions:
| Parameter | Purpose |
|---|---|
CMAKE_TOOLCHAIN_FILE | Buildroot auto-generated toolchain file containing all configurations including compiler and sysroot |
CMAKE_PREFIX_PATH | Points to the directory containing Qt5 CMake config files, allowing find_package(Qt5) to locate Qt |
Verifying Build Artifacts
$ file build/tspi-sysmonitor
tspi-sysmonitor: ELF 64-bit LSB executable, ARM aarch64, dynamically linked, ...
$ aarch64-buildroot-linux-gnu-readelf -d build/tspi-sysmonitor | grep NEEDED
(NEEDED) Shared library: [libQt5Widgets.so.5]
(NEEDED) Shared library: [libQt5Network.so.5]
(NEEDED) Shared library: [libQt5Core.so.5]
(NEEDED) Shared library: [libc.so.6]2
3
4
5
6
7
8
ARM aarch64 + dependency on libQt5Widgets.so.5 confirms a successful build.
qmake Cross-Compilation
The qmake provided by Buildroot has cross-compilation configuration built in — just call it directly.
Source code reuses the sample project tspi-sysmonitor
Build Commands
Note
If qmake is not found, check the Configuring PATH section at the beginning of this document to confirm that host/bin/ has been added to PATH.
# Confirm Buildroot qmake is in PATH
$ which qmake
/home/lckfb/TaishanPi-3-Linux/buildroot/output/rockchip_rk3576/host/bin/qmake
# Generate Makefile and compile
qmake tspi-sysmonitor.pro
make -j$(nproc)2
3
4
5
6
7
Verifying Artifacts
$ file tspi-sysmonitor
tspi-sysmonitor: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), dynamically linked, ...2
If you accidentally use the qmake installed via apt on the development machine, you will get an
Unknown specerror — usewhich qmaketo confirm the path points to Buildroot'shost/bin/qmake.
Troubleshooting Build Issues
1. command not found: aarch64-buildroot-linux-gnu-g++
The toolchain is not in PATH. Re-run export PATH=.../host/bin:$PATH.
2. Could not find a package configuration file provided by "Qt5"
find_package(Qt5) cannot find Qt5Config.cmake. Confirm the file exists:
find /home/lckfb/TaishanPi-3-Linux/buildroot/output/rockchip_rk3576/staging -name "Qt5Config.cmake"Once found, pass its directory to -DCMAKE_PREFIX_PATH. If not found, it means Buildroot has not enabled Qt — go back to ./build.sh bconfig and confirm BR2_PACKAGE_QT5 is selected.
3. cannot find -lQt5Widgets
The linker cannot find the Qt libraries. Check if the libraries exist in the sysroot:
ls buildroot/output/rockchip_rk3576/staging/usr/lib/libQt5Widgets*4. relocation R_X86_64_... error
x86_64 libraries from the development machine were linked, meaning CMAKE_TOOLCHAIN_FILE did not take effect. Confirm the cmake command correctly specifies the toolchainfile.cmake path.
5. Build artifact is x86-64 instead of ARM64
The development machine's compiler was used. Run which g++ to confirm the Buildroot toolchain has higher priority in PATH than the system path.
Next Steps
The core of command-line cross-compilation comes down to two things: the Buildroot toolchain PATH is correct, and CMake specifies toolchainfile.cmake and the Qt PREFIX_PATH. CMake is the universal approach; qmake is simpler but tied to Buildroot. After compilation, use file and readelf to confirm the artifact architecture and dependencies.
Next step: Deployment and Debugging