在Ubuntu 22.04 LTS(Jammy Jellyfish)环境下编译Qt 5.15,由于Ubuntu 22.04的官方仓库不再提供Qt 5.15系列的支持,您需要从源代码编译。以下是编译Qt 5.15的大致步骤:

步骤一:安装依赖项

确保系统中已经安装了必要的编译工具和依赖包,例如:

sudo apt update
sudo apt install build-essential libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev libxcb1-dev libxi-dev libgl1-mesa-dev libssl-dev gperf libicu-dev pkg-config bison flex qtchooser
sudo apt install libdbus-1-dev

步骤二:下载Qt 5.15源代码

访问Qt官网的Archive部分下载Qt 5.15的源代码包,例如qt-everywhere-src-5.15.2.zip.tar.xz格式。

wget https://download.qt.io/archive/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

步骤三:配置并编译Qt

创建一个构建目录,并在其中进行配置和编译。您可以选择只编译所需的模块,如qtbase、qtdeclarative等,或者编译全部模块。以下是一个基本的全局编译示例:

mkdir build
cd build
../configure -opensource -confirm-license -nomake examples -nomake tests -release
../configure -opensource -confirm-license -nomake examples -nomake tests -nomake qt3d -debug-and-release

# 如果您需要支持特定平台或特性,比如gtk2主题,则添加相关选项,例如:
# ../configure -opensource -confirm-license -nomake examples -nomake tests -release -qt-xcb -qt-gtk2

make -j 8
sudo make install

#其它编译命令
mkdir build && cd build
../configure -xcb -opensource -confirm-license -proprietary-codecs -no-feature-webengine-system-ninja -nomake examples -nomake tests
make -j
sudo make install

# 或者使用如下命令编译
# gmake && sudo gmake install

错误1

\qt-everywhere-src-5.15.3\qtbase\src\corelib\text\qbytearraymatcher.h 添加 #include <limits>

步骤四:配置环境变量

编译完成后,为了能够方便地使用新编译的Qt版本,可以更新环境变量PATH,将新安装的bin目录添加进去:

echo 'export PATH=/usr/local/Qt-5.15.2/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

请根据实际情况调整上述路径以指向实际安装位置。

注意事项

  • 编译过程可能需要较长时间,取决于您的硬件性能。
  • 在某些情况下,您可能还需要针对特定目标架构或交叉编译进行配置,这会涉及更多的编译参数。
  • Qt 5.15版本不再提供长期技术支持,可能存在与最新Linux内核或其他库不兼容的问题,因此在生产环境中谨慎考虑是否需要降级到这个版本。

更新于2024年

如果您是在2024年执行此操作,请务必检查Qt 5.15源代码与当前Ubuntu 22.04系统组件的兼容性,以及是否有新的已知问题需要解决。如果有可能,建议升级到更高版本的Qt,或者寻找社区维护的适用于Ubuntu 22.04的Qt 5.15 PPA。

02-15 05:25