Installing Cross-Compilation Toolchain
# Install ARM cross-compilation tools
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
# Alternative: Download toolchain from vendor
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
tar -xf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
Configuring Environment Variables
# Set up toolchain paths
export CROSS_COMPILE=arm-linux-gnueabihf-
export CC=${CROSS_COMPILE}gcc
export CXX=${CROSS_COMPILE}g++
export AR=${CROSS_COMPILE}ar
export STRIP=${CROSS_COMPILE}strip
# Or use full path approach
export TOOLCHAIN_PATH=/path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
export PATH=$TOOLCHAIN_PATH/bin:$PATH
Preparing Qt Source Code
# Download Qt source
wget https://download.qt.io/official_releases/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.tar.xz
tar -xf qt-everywhere-src-5.15.2.tar.xz
cd qt-everywhere-src-5.15.2
# Or clone via git
git clone https://github.com/qt/qt5.git
cd qt5
git checkout 5.15.2
./init-repository
Creating Cross-Compilation Specifications
Setting Up Device Configuration Directory
mkdir -p qtbase/mkspecs/linux-arm-gnueabihf-g++
Creating qmake.conf File
cat > qtbase/mkspecs/linux-arm-gnueabihf-g++/qmake.conf << 'EOF'
#
# qmake configuration for building with arm-linux-gnueabihf-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-linux-gnueabihf-gcc
QMAKE_CXX = arm-linux-gnueabihf-g++
QMAKE_LINK = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB = arm-linux-gnueabihf-g++
# modifications to linux.conf
QMAKE_AR = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabihf-objcopy
QMAKE_NM = arm-linux-gnueabihf-nm -P
QMAKE_STRIP = arm-linux-gnueabihf-strip
load(qt_config)
EOF
Creating qplatformdefs.h File
cat > qtbase/mkspecs/linux-arm-gnueabihf-g++/qplatformdefs.h << 'EOF'
/**************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
**
**************************************************************************/
#include "../linux-g++/qplatformdefs.h"
EOF
Configuring Build Options
Creating Configuration Script
cat > configure_qt_arm.sh << 'EOF'
#!/bin/bash
# Set installation prefix
QT_INSTALL_PREFIX=/opt/qt5-arm
QT_BUILD_DIR=$(pwd)/build-arm
# Create build directory
mkdir -p $QT_BUILD_DIR
cd $QT_BUILD_DIR
# Configure Qt
../configure \
-prefix $QT_INSTALL_PREFIX \
-xplatform linux-arm-gnueabihf-g++ \
-opensource \
-confirm-license \
-release \
-shared \
-no-opengl \
-no-xcb \
-no-gtk \
-no-feature-xcb \
-linuxfb \
-no-openssl \
-no-dbus \
-no-cups \
-no-glib \
-no-iconv \
-fontconfig \
-qt-freetype \
-qt-harfbuzz \
-qt-libpng \
-qt-libjpeg \
-qt-zlib \
-qt-pcre \
-make libs \
-nomake tools \
-nomake examples \
-nomake tests \
-skip qtwebengine \
-skip qtscript \
-skip qtdeclarative \
-skip qtmultimedia \
-skip qtwebkit \
-skip qttools \
-skip qtxmlpatterns \
-skip qtdoc \
-skip qtwebsockets \
-skip qtwebchannel \
-skip qtwayland \
-skip qtwinextras \
-skip qtsvg \
-v
EOF
chmod +x configure_qt_arm.sh
Advanced Configuration Options
cat > configure_qt_arm_full.sh << 'EOF'
#!/bin/bash
QT_INSTALL_PREFIX=/opt/qt5-arm-full
QT_BUILD_DIR=$(pwd)/build-arm-full
# Set library paths (if precompiled dependencies exist)
export PKG_CONFIG_LIBDIR=/opt/arm-rootfs/usr/lib/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=/opt/arm-rootfs
mkdir -p $QT_BUILD_DIR
cd $QT_BUILD_DIR
../configure \
-prefix $QT_INSTALL_PREFIX \
-xplatform linux-arm-gnueabihf-g++ \
-opensource \
-confirm-license \
-release \
-shared \
-opengl es2 \
-device-option CROSS_COMPILE=arm-linux-gnueabihf- \
-sysroot /opt/arm-rootfs \
-fontconfig \
-system-freetype \
-system-harfbuzz \
-system-libpng \
-system-libjpeg \
-system-zlib \
-qt-pcre \
-ssl \
-openssl-linked \
-I/opt/arm-rootfs/usr/include/openssl \
-L/opt/arm-rootfs/usr/lib \
-make libs \
-make tools \
-nomake examples \
-nomake tests \
-v
EOF
chmod +x configure_qt_arm_full.sh
Building Process
Running Configuration
# Execute configuration script
./configure_qt_arm.sh
# Verify configuration output
# Confirm correct cross-compiler paths appear in output
Starting Compilation
cd build-arm
# Compile with multiple cores (adjust -j parameter based on CPU cores)
make -j$(nproc)
# Reduce parallelism if memory is limited
make -j4
Installation
# Install to specified directory
sudo make install
# Or install to temporary directory then copy
make install INSTALL_ROOT=/tmp/qt5-arm-install
Verifying Build Results
Checking Generated Files
# Check installation directory
ls -la /opt/qt5-arm/
# Check library files
ls -la /opt/qt5-arm/lib/
# Verify executable architecture
file /opt/qt5-arm/lib/libQt5Core.so.5
Creating Test Program
// test.cpp
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qDebug() << "Qt version:" << QT_VERSION_STR;
qDebug() << "Hello Qt Cross Compilation!";
return 0;
}
# Compile test program
/opt/qt5-arm/bin/qmake -project
echo "QT += core" >> test.pro
echo "CONFIG += console" >> test.pro
/opt/qt5-arm/bin/qmake
make
# Check generated executable
file test
Common Issues and Solutions
Handling Compilation Errors
# Clean build directory
make clean
make distclean
# Reconfigure after cleaning
rm -rf build-arm
./configure_qt_arm.sh
Resovling Dependency Issues
# If dependencies are missing, disable related features
-no-openssl # Disable SSL support
-no-dbus # Disable D-Bus support
-no-glib # Disable GLib support
-no-fontconfig # Disable fontconfig support
Memory Limitation Handling
# Reduce parallel compilation threads
make -j1
# Add swap space if needed
sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152
sudo mkswap /swapfile
sudo swapon /swapfile
Optimization Reocmmendations
Build Optimizations
# Add optimization flags during configure
-optimize-size # Optimize for size
-ltcg # Link-time code generation
Module Selection
# Include only required modules
-skip qtwebengine
-skip qtmultimedia
-skip qtdeclarative
# Select based on actual needs
Static Compilation
# For static libraries
-static
-static-runtime
This comprehensive workflow should enable successful cross-compilation of Qt libraries. Adjust configuration parameters according to your specific target platform and requirements.