Assume you have a host(x86_64) build of qtbase, like following:
1 2 3 4 5 6 7 |
cd ~/qt git clone git://code.qt.io/qt/qtbase.git mkdir qtbase-build cd qtbase-build ../qtbase/configure -developer-build -opensource -confirm-license -nomake examples -nomake tests -verbose cmake --build . --parallel -j8 |
Some extra work to setup system:
1 2 3 4 5 6 7 |
sudo apt install binfmt-support cd ~/Downloads wget https://download.qt.io/development_releases/prebuilt/boot2qt/gatesgarth/b2qt-x86_64-meta-toolchain-b2qt-ci-sdk-qemuarm64-a9d5156a.sh chmod +x b2qt-x86_64-meta-toolchain-b2qt-ci-sdk-qemuarm64-a9d5156a.sh sudo ./b2qt-x86_64-meta-toolchain-b2qt-ci-sdk-qemuarm64-a9d5156a.sh -y -d /opt/b2qt/3.2 sudo update-binfmts --package qemu-aarch64 --install aarch64 /opt/b2qt/3.2/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-aarch64 --magic '\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
Create a prefix.sh file for cross compile:
1 2 3 4 |
cd ~/qt vi prefix.sh chmod +x prefix.sh |
Contents like:
1 2 3 4 5 6 7 |
#!/bin/bash unset LD_LIBRARY_PATH . /opt/b2qt/3.2/environment-setup-cortexa57-poky-linux export PATH=/snap/bin/cmake:$PATH; unset QMAKESPEC "$@" |
Build qtbase for arm64:
1 2 3 4 5 6 |
cd ~/qt mkdir qtbase-arm64-build cd qtbase-arm64-build ~/qt/prefix.sh /home/liangqi/qt/qtbase/configure -release -force-debug-info -developer-build -no-warnings-are-errors -nomake examples -qt-harfbuzz -device linux-generic-g++ -device-option CROSS_COMPILE=/opt/b2qt/3.2/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux- -device-option DISTRO_OPTS=boot2qt -no-feature-forkfd_pidfd -- -DCMAKE_TOOLCHAIN_FILE=/opt/b2qt/3.2/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake -DQT_FORCE_BUILD_TOOLS=ON -DQT_HOST_PATH=/home/liangqi/qt/qtbase-build -DQT_BUILD_TESTS=OFF -DCMAKE_AUTOGEN_VERBOSE=ON -DCMAKE_MESSAGE_LOG_LEVEL=STATUS ~/qt/prefix.sh cmake --build . --parallel -j8 |
Build auto tests in qtbase for arm64:
1 2 3 4 5 6 |
cd ~/qt mkdir qtbase-arm64-tests cd qtbase-arm64-tests ~/qt//prefix.sh /home/liangqi/qt/qtbase-arm64-build/libexec/qt-internal-configure-tests -DCMAKE_AUTOGEN_VERBOSE=ON -DCMAKE_MESSAGE_LOG_LEVEL=STATUS -S /home/liangqi/qt/qtbase -B . ~/qt/prefix.sh cmake --build . --parallel -j8 |
1 2 3 |
cd tests/auto/gui/kernel/qwindow file ./tst_qwindow |
Now we can see tst_qwindow is a aarch64 binary:
1 2 |
./tst_qwindow: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=c476475489304f84628932469d44698ae7bcb9be, for GNU/Linux 3.14.0, with debug_info, not stripped |
Run it!
1 2 3 4 |
export QEMU_LD_PREFIX=/opt/b2qt/3.2/sysroots/cortexa57-poky-linux export QT_QPA_PLATFORM=offscreen ./tst_qwindow |
Reference: