Gallery

Blog | en| ru|

Patch Set for Building Qt 5.15.16 LTS in Ubuntu Linux 24.04 and Later

Contents


Download patch file: qt-5.15.16-ubuntu-universal-build.patch


Most of the existing development setups use a prebuilt Qt library version 5 provided by the Linux distribution. However, when the build requires a completely homogeneous, static, or frozen version of the Qt 5 library, the prebuilt packages are not enough. This article considers a frozen version build of Qt 5.15.16 LGPL. The patch file is published under GNU Lesser General Public License version 3 as well as the original Qt library sources. It integrates and verifies the additional patches made by the respective maintainers of the following Ubuntu Qt packages:

The packages listed above are built and patched for Ubuntu 24.04 LTS (noble). The decision was made to freeze this version for this article, as it strives to provide the Qt version as close as possible to the LTS version provided in the official repository. The build process also freezes the version of some assisting software, such as Google Protobuf.

Qt WebEngine version

To maintain the maximum compatibility and apply some workarounds, WebEngine version in the original clone script should be fixed! To use the patch, please ensure that the qtwebengine submodule is set to v5.15.16-lts-lgpl tag.


Prerequisites

clang

The build process described here uses Clang 20 from LLVM packages, for better optimisation and proper compiling of C++ workarounds. If the LLVM installation is on the target system, the shared libraries libc++abi.so.1 and libc++.so.1 should be moved or symlinked to the directory mentioned in LD_LIBRARY_PATH, as the Qt build system uses them to prepare clangd compatibility layer and documentation parsers. If Clang is not used, no additional compiler adjustments should be done.

System Packages

The following packages should be installed in the target system to successfully build the Qt library. This is not a complete list: the final package set depends on the build purposes and usage requirements. All the packages could be installed with one APT command:

sudo apt install ruby \
    perl \
    ninja-build \
    '^libxcb.*-dev' \
    libx11-xcb-dev \
    libglu1-mesa-dev \
    libxrender-dev \
    libxi-dev \
    libxkbcommon-dev \
    libxkbcommon-x11-dev \
    flex \
    bison \
    gperf \
    libicu-dev \
    libxslt-dev \
    libcap-dev \
    libegl1-mesa-dev \
    libevent-core-2.1-7t64 \
    libevent-dev \
    libevent-extra-2.1-7t64 \
    libevent-openssl-2.1-7t64 \
    libevent-pthreads-2.1-7t64 \
    libnspr4-dev \
    libnss3-dev \ 
    libpci-dev \
    libasound2-dev \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev \
    libgstreamer-plugins-good1.0-dev \
    libminizip-dev \
    libzzip-dev \ 
    libinput-dev \
    libxshmfence-dev \
    libpq-dev \
    libabsl-dev \
    libbluetooth-dev \
    bluez \
    bluez-tool \
    libsqlite3-dev \
    libmysqlclient-dev \
    libsqlitecpp-dev \
    libprotozero-dev

The package libgstreamer-plugins-bad1.0-dev is here omitted to avoid unnecessary installation of many obsolete multimedia libraries that the user could intend to retrieve from other sources.

Boost Library

Boost libraries from the Ubuntu repository could be incompatible with Clang-based builds, and they must also include the signals component excluded from the main Boost source tree, to stay compatible with Qt 5. To ensure this, the Boost library version 1.87.0 should be manually built and installed from sources.

# Cloning Boost
git clone -b boost-1.87.0 --recurse-submodules git@github.com:boostorg/boost.git libboost
# Adding Signals library
git clone https://github.com/boostorg/signals.git libboost/libs/signals
# Compiling with internal b2 build system
cd libboost
./bootstrap.sh --with-toolset=clang --with-python=python3
./b2 -j4 toolset=clang variant=release link=shared threading=multi
./b2 -j4 toolset=clang variant=release link=shared threading=multi headers
sudo ./b2 -j4 toolset=clang variant=release link=shared threading=multi install

NOTE: Use --prefix=<path> option to install the libraries in the dedicated XDG tree.

3rd Party Software

Some 3rd party software essential to building Qt 5 should have also been built in place to avoid ABI incompatibilities and segmentation faults. All the build operations assume that the Release version is built with the clang compiler, as described above. The native Linux compiler configuration could be set in this case using the following flags:

CC=clang CXX=clang++

For CMake:

-DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release

The flag -DCMAKE_POLICY_VERSION_MINIMUM=3.5 is added as a workaround for the newer versions of CMake incompatible with some old policy definitions.

The following table contains the exact versions and build parameters. The names are linked with the corresponding Git repository pages.

Software Version (Git tag) Build System Build Flags
Node.js v25.1.0 Custom configure --use_clang --fully-static --ninja --v8-enable-hugepage --v8-enable-snapshot-compression --with-intl=full-icu
assimp v6.0.2 CMake -DASSIMP_BUILD_ASSIMP_TOOLS=ON
Google Protobuf v3.21.12 CMake -Dprotobuf_BUILD_LIBPROTOC=ON -Dprotobuf_BUILD_PROTOC_BINARIES=ON -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF -DABSL_PROPAGATE_CXX_STD=ON -Dprotobuf_MODULE_COMPATIBLE=ON -DABSL_PROPAGATE_CXX_STD=ON
librapidjson - CMake -DRAPIDJSON_BUILD_CXX17=ON -DRAPIDJSON_BUILD_CXX20=ON -DRAPIDJSON_HAS_STDSTRING=ON

Building Shared Qt Library

IMPORTANT!!!

If the clang compiler and LLVM infrastructure are installed from source or in a non-standard XDG tree, the environment variable LLVM_INSTALL_DIR must contain the path to its installation prefix directory. This is essential to build Qt documentation and code analyser integration!

Setting Up Qt Sources

This ensures the QtWebEngine component is forced to v5.15.16-lts-lgpl Git tag.

git clone -b v5.15.16-lts-lgpl https://code.qt.io/qt/qt5.git qt5
cd qt5
perl init-repository
cd qtwebengine
git checkout v5.15.16-lts-lgpl
cd ..
git submodule update

Applying Patch

Assuming that the patch file qt-5.15.16-ubuntu-universal-build.patch has already been downloaded into the parent directory:

git apply ../qt-5.15.16-ubuntu-universal-build.patch

Building and Installation

The -prefix option can be used here to the XDG installation prefix, and -I, -L configure options to set the proper library prefix paths.

export LLVM_INSTALL_DIR=/util/llvm # Optional, see above

./configure -platform linux-clang \
    -opensource \
    -confirm-license \
    -c++std c++17 \
    -shared \
    -strip \
    -release \
    -system-assimp \
    -pulseaudio \
    -system-tiff \
    -system-webp \
    -sql-psql \
    -system-zlib \
    -system-libjpeg \
    -system-libpng \
    -system-freetype \
    -system-pcre \
    -system-harfbuzz \
    -system-sqlite \
    -libudev \
    -libinput \
    -xkbcommon \
    -xcb \
    -linuxfb \
    -xcb-xlib \
    -opengl desktop \
    -linker lld \
    -no-use-gold-linker \
    -webengine-alsa \
    -webengine-pulseaudio \
    -webengine-icu \
    -qt-webengine-ffmpeg \
    -webengine-opus \
    -webengine-webp \
    -webengine-printing-and-pdf \
    -webengine-webrtc

make -j4
sudo make install
make -j2 docs
sudo make install_docs

Cleanup

make -j4 distclean
find . -name *.so -exec rm {} \;
find . -name *.so.* -exec rm {} \;

Building Static Qt Library (optional)

NOTE: Shared and static versions of the library cannot be installed in the same XDG tree as they use different versions of qmake! Use -prefix option to select the proper location!

-I, -L configure options could be used to set the proper library prefix paths as described above. After the patches are successfully applied, the library can be built immediately:

export LLVM_INSTALL_DIR=/util/llvm # Optional, see above

./configure -platform linux-clang \
    -opensource \
    -confirm-license \
    -c++std c++17 \
    -static \
    -release \
    -nomake examples \
    -nomake tests \
    -skip wayland \
    -skip purchasing \
    -skip serialbus \
    -skip qtserialport \
    -skip script \
    -skip scxml \
    -skip speech \
    -qt-assimp \
    -pulseaudio \
    -qt-tiff \
    -qt-webp \
    -sql-psql \
    -qt-zlib \
    -no-libjpeg \
    -qt-libpng \
    -qt-freetype \
    -qt-pcre \
    -qt-harfbuzz \
    -qt-sqlite \
    -opengl desktop \
    -linker lld \
    -no-use-gold-linker

make -j4
sudo make install