Qt5.14.2 本地编译及安装记录
概要:本文记录了在 RK3588 上手动编译并安装 Qt 5.14.2 的完整过程,包括所需依赖的安装、源码下载与编译配置,以及常见问题的解决方案。
1. 安装依赖
首先,确保你的系统安装了编译 Qt 所需的依赖:
sudo apt update
sudo apt install build-essential libgl1-mesa-dev libxkbcommon-dev libxkbcommon-x11-dev \
libxcb-xinerama0-dev libxcb-xinerama0 libxcb-icccm4-dev libxcb-image0-dev \
libxcb-keysyms1-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-sync-dev \
libxcb-xfixes0-dev libxcb-xkb-dev libxcb1-dev libxcb1 libxrender-dev libx11-dev \
libx11-xcb-dev libxi-dev libxext-dev libfontconfig1-dev libfreetype6-dev libpng-dev \
libjpeg-dev libssl-dev libdbus-1-dev libicu-dev libpulse-dev libasound2-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
2. 下载 Qt 5.14.2 源码
从 Qt 官方网站下载 Qt 5.14.2 的源码包:
wget https://download.qt.io/archive/qt/5.14/5.14.2/single/qt-everywhere-src-5.14.2.tar.xz
3. 解压源码包
tar -xvf qt-everywhere-src-5.14.2.tar.xz
cd qt-everywhere-src-5.14.2
4. 配置 Qt 编译选项
使用 configure 脚本来配置 Qt 的编译选项:
./configure -prefix /opt/Qt5.14.2 -opensource -confirm-license -release \
-nomake examples -nomake tests -no-openssl -no-icu -skip qtlocation
选项说明
-prefix /opt/Qt5.14.2:指定 Qt 的安装目录。-opensource -confirm-license:接受开源许可证。-release:编译发布版本。-nomake examples -nomake tests:不编译示例和测试代码。-no-openssl:禁用 OpenSSL(如果不需要 SSL 支持)。-no-icu:禁用 ICU(如果不需要国际化支持)。
5. 编译并安装 Qt
使用 make 命令编译 Qt,然后使用 make install 安装到指定目录:
make -j$(nproc)
sudo make install
-j$(nproc) 选项会根据你的 CPU 核心数并行编译,以加快编译速度。
6. 验证安装
qmake --version
你应该看到类似于 QMake version 3.1 和 Using Qt version 5.14.2 的输出结果。
7. 问题解决
7.1 缺少 Python2
执行 make install 后出现以下错误:
sh: 1: python: not found
Project ERROR: Building QtQml requires Python.
make: *** [Makefile:352:module-qtdeclarative-install_subtargets] 错误 3
解决方案:安装 Python2
sudo apt install python
7.2 编译 QtLocation 报错
错误信息:
/usr/bin/ld: 找不到 -lclip2tri
/usr/bin/ld: 找不到 -lpoly2tri
/usr/bin/ld: 找不到 -lclipper
collect2: error: ld returned 1 exit status
make: *** [Makefile:828:module-qtlocation-install_subtargets] 错误 2
原因:缺少 libclip2tri、libpoly2tri 和 libclipper 库,这些是 QtLocation 模块的依赖项。
解决方案:如果不需要 QtLocation 模块,则跳过它:
./configure -prefix /opt/Qt5.14.2 -opensource -confirm-license -release \
-nomake examples -nomake tests -no-openssl -no-icu -skip qtlocation
7.3 缺少 wayland-client.h
错误信息:
fatal error: wayland-client.h: 没有那个文件或目录
原因:系统缺少 wayland-client.h 头文件,导致 qtmultimedia 模块编译失败。
解决方案:安装 Wayland 开发库:
sudo apt update
sudo apt install libwayland-dev
make install
7.4 缺少 libqtopenwnn.a 文件
错误信息:
g++: error: .../qtvirtualkeyboard/lib/libqtopenwnn.a: 没有那个文件或目录
make: *** [Makefile:906:module-qtvirtualkeyboard-install_subtargets] 错误 2
原因:qtvirtualkeyboard 模块依赖于 libqtopenwnn.a,但该库未正确编译或缺失。
解决方案:
-
检查 OpenWNN 库是否已编译:
ls /root/Qt-5.14.2/qt-everywhere-src-5.14.2/qtvirtualkeyboard/lib/libqtopenwnn.a -
如果文件不存在,尝试手动编译:
cd /root/Qt-5.14.2/qt-everywhere-src-5.14.2/qtvirtualkeyboard/src/plugins/openwnn make -
确保编译成功后,重新运行
make install:make install
留下评论