Compiling Qt6 from source

Compiling Qt

Here is a summary on how to compile Qt6.9.1 from source on Ubuntu 24.04. I wanted a minimal and up-to-date version of the Qt library, so I only included the base abd serial port modules. Even though Ubuntu 24.04 uses Wayland I opted for the X11 backend because the QtWayland module includes too much stuff I don’t need, such as QML.

It took me a while to get this right, especially the X11 backend. I hope this information will reduce your effort to get Qt compiled. As this is custom version of Qt, I chose to install it in /opt/Qt6_9.

First download the qt source code and unpack:

wget https://download.qt.io/official_releases/qt/6.9/6.9.1/single/qt-everywhere-src-6.9.1.tar.xz
xz -d qt-everywhere-src-6.9.1.tar.xz
tar -xf qt-everywhere-src-6.9.1.tar
rm qt-everywhere-src-6.9.1.tar

Before compiling, the following dependencies need to be installed (Ubuntu 24.04):

apt install \
    libfontconfig1-dev \
    libfreetype-dev \
    libgtk-3-dev \
    libx11-dev \
    libx11-xcb-dev \
    libxcb-cursor-dev \
    libxcb-glx0-dev \
    libxcb-icccm4-dev \
    libxcb-image0-dev \
    libxcb-keysyms1-dev \
    libxcb-randr0-dev \
    libxcb-render-util0-dev \
    libxcb-shape0-dev \
    libxcb-shm0-dev \
    libxcb-sync-dev \
    libxcb-util-dev \
    libxcb-xfixes0-dev \
    libxcb-xkb-dev \
    libxcb1-dev \
    libxext-dev \
    libxfixes-dev \
    libxi-dev \
    libxkbcommon-dev \
    libxkbcommon-x11-dev \
    libxrender-dev

For convenience, I made a small script called bootstrap.sh:

#!/bin/sh

rm -rf qt-build
mkdir -p qt-build
cd qt-build
../configure -prefix /opt/Qt6_9 -xcb -xcb-xlib -opensource -shared -submodules qtbase,qtserialport
cmake --build . --parallel
cmake --install .

Execute the bootstrap.sh

Building software

Building software with the custom version of Qt is best done by using qt-cmake, a wrapper around the system’s cmake that will set the Qt paths to the correct location. As an example. here is my bash script for setting up a compilation for LunaPnR:

rm -rf build
mkdir build
cd build
/opt/Qt6_9/bin/qt-cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..