赞
踩
在 ARM 架构下,UOS 系统,需要使用 Qt 5.15.2 版本环境,所以只能通过源码编译的形式进行 Qt 环境的部署。
软硬件相关信息:
这里选择的是国内的镜像地址进行下载源码。
Qt 5.15.2: http://mirrors.ustc.edu.cn/qtproject/archive/qt/5.15/5.15.2/single/
Qt Creator: http://mirrors.ustc.edu.cn/qtproject/archive/qtcreator/
需要注意的是,QtCreator 的版本要和 Qt 大版本对应。比如,Qtcreator 11 版本采用 Qt 6 编译,如果你下载的 Qt 源码是 Qt 5 版本的,那么编译时,会找不到 Qt 6 相关的 cmake 文件,无法进行编译。是否适合当前版本,可以通过 qt-creator-opensource-src
里的 README.md
中介绍确定对应的版本。
下载完成后,使用 tar 命令进行解压
tar -zxvf qt-everywhere-src-5.15.2.tar.xz
tar -zxvf qt-creator-opensource-src-7.0.2.tar.gz
安装 Qt 所需的依赖:
sudo apt install build-essential libgl1-mesa-dev libxkbcommon-dev libnss3-dev libdbus-1-dev gperf flex bison
安装 xcb 相关:
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
这一步比较关键,因为涉及到编译之后有 libqxcb.so
,如果缺失会导致错误。
如果需要使用到 QWebEngine 模块,那么需要安装以下依赖库:
sudo apt install libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libxtst-dev libxss-dev libdbus-1-dev libevent-dev libfontconfig1-dev libcap-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libegl1-mesa-dev gperf bison nodejs
进入解压后的 qt-everywhere-src-5.15.2
目录,开始配置:
./configure -prefix /home/leo/Qt -opensource -confirm-license -nomake examples -release
-prefix /home/leo/Qt
: 指定 Qt 的安装路径-opensource
: 指定使用开源版本-nomake examples
: 不编译 examples-release
: release 模式这个步骤会检查相关的库是否存在,若不存在则将缺少的安装。
安装完缺失的依赖库后,记得先删除 config.cache
缓存文件。
或者使用脚本运行,创建 run.sh
脚本:
#! /bin/bash
./configure -prefix /home/leo/Qt/5 \
-opensource -confirm-license \
-nomake examples \
-nomake tests \
-release \
-skip qt3d \
-skip qtcharts \
-skip qtandroidextras \
-skip qtlocation \
-skip qtmultimedia \
-skip qtsensors \
-skip qtserialbus \
-skip qtserialport \
-skip qtwayland
可以指定跳过编译哪些模块以加快编译速度
开始编译:
make
此过程示机器性能不同,时长不同。
在编译过程中,可能会遇到一些依赖问题,需要根据实际情况进行解决。
当编译完成后,即可安装了
make install
输出信息:
cd doc/src/cmake/ && ( test -e Makefile || /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtbase/bin/qmake -o Makefile /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc/src/cmake/cmake.pro ) && make -f Makefile install
make[2]: 进入目录“/data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc/src/cmake”
make[2]: 对“install”无需做任何事。
make[2]: 离开目录“/data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc/src/cmake”
cd doc/ && ( test -e Makefile || /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtbase/bin/qmake -o Makefile /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc/doc.pro ) && make -f Makefile install
make[2]: 进入目录“/data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc”
make[2]: 对“install”无需做任何事。
make[2]: 离开目录“/data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc/doc”
make[1]: 离开目录“/data/home/leo/Documents/qt-everywhere-src-5.15.2/qtdoc”
会安装到 /home/leo/Qt
路径下,安装完之后可查看结果。
编译 Qt Creator 则可使用 cmake 工具进行编译:
cd qt-creator-opensource-src
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/leo/Qt -DCMAKE_INSTALL_PREFIX=/home/leo/Qt/Tool/QtCreator
cmake --build build --target=install
输出信息:
[100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/avddialog.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/avdmanageroutputparser.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/certificatesmodel.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/createandroidmanifestwizard.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/javaeditor.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/javaindenter.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/javalanguageserver.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/javaparser.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/splashscreencontainerwidget.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/splashscreenwidget.cpp.o [100%] Building CXX object src/plugins/android/CMakeFiles/Android.dir/Android_autogen/EWIEGA46WW/qrc_android.cpp.o [100%] Linking CXX shared library ../../../lib/qtcreator/plugins/libAutoTest.so [100%] Built target AutoTest [100%] Linking CXX shared library ../../../lib/qtcreator/plugins/libAndroid.so [100%] Built target Android -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_hr.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_ja.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_pl.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_ru.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_sl.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_uk.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_zh_CN.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/qtcreator/translations/qtcreator_zh_TW.qm -- Installing: /home/leo/Qt/Tool/QtCreator/share/applications -- Installing: /home/leo/Qt/Tool/QtCreator/share/applications/org.qt-project.qtcreator.desktop -- Installing: /home/leo/Qt/Tool/QtCreator/share/metainfo/org.qt-project.qtcreator.appdata.xml
看到以上信息,则表示安装完成。
leo@leo-PC:/data/home/leo/Qt/Tool/QtCreator/bin$ ./qtcreator
./qtcreator: relocation error: /data/home/leo/Qt/Tool/QtCreator/bin/../lib/qtcreator/libUtils.so.7: symbol _ZNK11QPushButton9hitButtonERK6QPoint version Qt_5 not defined in file libQt5Widgets.so.5 with link time reference
前往安装目录运行会提示以上错误。
配置 Qt 环境:
leo@leo-PC:~$ vim ~/.bashrc
在尾部加入以下内容:
export QTDIR=/home/leo/Qt/5.15.2
export PATH=$QTDIR/bin:$PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins/platforms
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
刷新,qmake 测试
leo@leo-PC:~$ source ~/.bashrc
leo@leo-PC:~$ qmake -v
QMake version 3.1
Using Qt version 5.15.2 in /home/leo/Qt/5.15.2/lib
能看到输出的版本信息,则说明配置成功。
WARNING: gperf is required to build QWebEngine.
解决方法:
sudo apt-get install gperf
WARNING: flex is required to build QWebEngine.
解决方法:
sudo apt-get install flex
WARNING: bison is required to build QWebEngine.
解决方法:
sudo apt-get install bison
XCB Util >= 0.3.9... no
https://www.x.org/releases/individual/xcb/ 下载大于 0.3.9 的版本,我这里下载的是 xcb-util-0.4.1. tar. gz,解压并进入文件夹
./configure
make
sudo make install
再次执行 Qt 的 configure 命令,可以看到变成了 Yes
Package nss was not found in the pkg-config search path.
Perhaps you should add the directory containing `nss.pc'
to the PKG_CONFIG_PATH environment variable
No package 'nss' found
Could not run pkg-config.
解决方法:
sudo apt install libnss3-dev
ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned non-zero exit code. pkgresult = exec_script(pkg_config_script, args, "value") ^---------- Current dir: /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtwebengine/src/pdf/release/ Command: /usr/bin/python2 /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtwebengine/src/3rdparty/chromium/build/config/linux/pkg-config.py -p pkg-config dbus-1 Returned 1. stderr: Package dbus-1 was not found in the pkg-config search path. Perhaps you should add the directory containing `dbus-1.pc' to the PKG_CONFIG_PATH environment variable No package 'dbus-1' found Could not run pkg-config. See //build/config/linux/dbus/BUILD.gn:12:1: whence it was called. pkg_config("dbus") { ^------------------- See //dbus/BUILD.gn:45:22: which caused the file to be included. public_configs = [ "//build/config/linux/dbus" ] ^-------------------------- Project ERROR: GN run error!
解决方法:
sudo apt install libdbus-1-dev
ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned non-zero exit code. pkgresult = exec_script(pkg_config_script, args, "value") ^---------- Current dir: /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtwebengine/src/pdf/release/ Command: /usr/bin/python2 /data/home/leo/Documents/qt-everywhere-src-5.15.2/qtwebengine/src/3rdparty/chromium/build/config/linux/pkg-config.py -p pkg-config xkbcommon Returned 1. stderr: Package xkbcommon was not found in the pkg-config search path. Perhaps you should add the directory containing `xkbcommon.pc' to the PKG_CONFIG_PATH environment variable No package 'xkbcommon' found Could not run pkg-config. See //ui/events/keycodes/BUILD.gn:12:3: whence it was called. pkg_config("xkbcommon") { ^------------------------ See //ui/events/ozone/layout/BUILD.gn:42:15: which caused the file to be included. deps += [ "//ui/events/keycodes:xkb" ] ^------------------------- Project ERROR: GN run error!
解决方法:
sudo apt install libxkbcommon-dev
FAILED: obj/third_party/libjpeg_turbo/simd/jidctfst-neon.o /usr/bin/gcc -MMD -MF obj/third_party/libjpeg_turbo/simd/jidctfst-neon.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -DOFFICIAL_BUILD -DTOOLKIT_QT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DNO_UNWIND_TABLES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../../3rdparty/chromium/third_party/libjpeg_turbo -Igen -I../../3rdparty/chromium -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fPIC -pipe -pthread -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -fno-delete-null-pointer-checks -Wno-comments -Wno-packed-not-aligned -Wno-dangling-else -Wno-missing-field-initializers -Wno-unused-parameter -fno-omit-frame-pointer -g0 -fvisibility=hidden -O3 -fno-ident -fdata-sections -ffunction-sections -std=gnu11 -c ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c -o obj/third_party/libjpeg_turbo/simd/jidctfst-neon.o ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c: In function ‘jsimd_idct_ifast_neon’: ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:87:28: error: incompatible types when initializing type ‘int64_t’ {aka ‘long int’} using type ‘int64x1_t’ int64_t left_ac_bitmap = vreinterpret_s64_s16(vget_low_s16(bitmap)); ^~~~~~~~~~~~~~~~~~~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:88:29: error: incompatible types when initializing type ‘int64_t’ {aka ‘long int’} using type ‘int64x1_t’ int64_t right_ac_bitmap = vreinterpret_s64_s16(vget_high_s16(bitmap)); ^~~~~~~~~~~~~~~~~~~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:408:29: note: use -flax-vector-conversions to permit conversions between vectors with differing element types or numbers of subparts vaddq_s8(cols_01_s8, vdupq_n_u8(CENTERJSAMPLE))); ^~~~~~~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:408:50: error: incompatible type for argument 2 of ‘vaddq_s8’ vaddq_s8(cols_01_s8, vdupq_n_u8(CENTERJSAMPLE))); ^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:31: /usr/lib/gcc/aarch64-linux-gnu/8/include/arm_neon.h:723:36: note: expected ‘int8x16_t’ but argument is of type ‘uint8x16_t’ vaddq_s8 (int8x16_t __a, int8x16_t __b) ~~~~~~~~~~^~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:410:50: error: incompatible type for argument 2 of ‘vaddq_s8’ vaddq_s8(cols_45_s8, vdupq_n_u8(CENTERJSAMPLE))); ^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:31: /usr/lib/gcc/aarch64-linux-gnu/8/include/arm_neon.h:723:36: note: expected ‘int8x16_t’ but argument is of type ‘uint8x16_t’ vaddq_s8 (int8x16_t __a, int8x16_t __b) ~~~~~~~~~~^~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:412:50: error: incompatible type for argument 2 of ‘vaddq_s8’ vaddq_s8(cols_23_s8, vdupq_n_u8(CENTERJSAMPLE))); ^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:31: /usr/lib/gcc/aarch64-linux-gnu/8/include/arm_neon.h:723:36: note: expected ‘int8x16_t’ but argument is of type ‘uint8x16_t’ vaddq_s8 (int8x16_t __a, int8x16_t __b) ~~~~~~~~~~^~~ ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:414:50: error: incompatible type for argument 2 of ‘vaddq_s8’ vaddq_s8(cols_67_s8, vdupq_n_u8(CENTERJSAMPLE))); ^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jidctfst-neon.c:31: /usr/lib/gcc/aarch64-linux-gnu/8/include/arm_neon.h:723:36: note: expected ‘int8x16_t’ but argument is of type ‘uint8x16_t’ vaddq_s8 (int8x16_t __a, int8x16_t __b) ~~~~~~~~~~^~~ [5/547] /usr/bin/gcc -MMD -MF obj/third_party/libjpeg_turbo/simd/jdsample-neon.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -DOFFICIAL_BUILD -DTOOLKIT_QT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DNO_UNWIND_TABLES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../../3rdparty/chromium/third_party/libjpeg_turbo -Igen -I../../3rdparty/chromium -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fPIC -pipe -pthread -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -fno-delete-null-pointer-checks -Wno-comments -Wno-packed-not-aligned -Wno-dangling-else -Wno-missing-field-initializers -Wno-unused-parameter -fno-omit-frame-pointer -g0 -fvisibility=hidden -O3 -fno-ident -fdata-sections -ffunction-sections -std=gnu11 -c ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jdsample-neon.c -o obj/third_party/libjpeg_turbo/simd/jdsample-neon.o ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jdsample-neon.c: In function ‘jsimd_h2v1_upsample_neon’: ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jdsample-neon.c:507:36: warning: missing braces around initializer [-Wmissing-braces] uint8x16x2_t output_pixels = { samples, samples }; ^ { } ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jdsample-neon.c: In function ‘jsimd_h2v2_upsample_neon’: ../../3rdparty/chromium/third_party/libjpeg_turbo/simd/arm/common/jdsample-neon.c:548:36: warning: missing braces around initializer [-Wmissing-braces] uint8x16x2_t output_pixels = { samples, samples }; ^ { } [6/547] /usr/bin/gcc -MMD -MF obj/third_party/libjpeg_turbo/libjpeg/jdcolor.o.d -DWITH_SIMD -DNO_GETENV -DUSE_UDEV -DUSE_AURA=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -DOFFICIAL_BUILD -DTOOLKIT_QT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DNO_UNWIND_TABLES -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -Igen -I../../3rdparty/chromium -I../../3rdparty/chromium/third_party/libjpeg_turbo -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fPIC -pipe -pthread -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -fno-delete-null-pointer-checks -Wno-comments -Wno-packed-not-aligned -Wno-dangling-else -Wno-missing-field-initializers -Wno-unused-parameter -O2 -fno-ident -fdata-sections -ffunction-sections -fno-omit-frame-pointer -g0 -fvisibility=hidden -std=gnu11 -c ../../3rdparty/chromium/third_party/libjpeg_turbo/jdcolor.c -o obj/third_party/libjpeg_turbo/libjpeg/jdcolor.o ninja: build stopped: subcommand failed.
解决方法:
这个错误是由于 QWebengine 模块的 chromium 包含的 third_party 里第三方库 libjpeg_turbo 在 ARM 下的兼容问题,可以逐个对比 GitHub 的代码修改错误,也可以尝试将最新的 libjpeg_turbo 源文件覆盖。
leo@leo-PC:/data/home/leo/Qt/Tool/QtCreator/bin$ ./qtcreator
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "/home/leo/Qt/5.15.2/plugins/platforms"
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: linuxfb (from /home/leo/Qt/5.15.2/plugins/platforms), minimal (from /home/leo/Qt/5.15.2/plugins/platforms), offscreen (from /home/leo/Qt/5.15.2/plugins/platforms), vnc (from /home/leo/Qt/5.15.2/plugins/platforms), webgl (from /home/leo/Qt/5.15.2/plugins/platforms), linuxfb, minimal, offscreen, vnc, webgl.
已放弃
查看 /home/leo/Qt/5.15.2/plugins/platforms
安装目录下是否有 libqxcb.so
库,如果没有,则说明源码编译不完整。
需要安装 xcb 相关的库
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
然后重新编译尝试。
以上便是在 ARM 架构平台的 Linux 系统上编译 Qt 整个过程,在编译过程中,需要特别注意的便是依赖库的完整性,如果缺失一些依赖库,Qt 并不会直接报错,编译之后才发现缺失依赖库,有的组件用不了。尤其是 libqxcb.so
库,最开始编译的时候,没用生成它,导致程序无法启动。
所以要特别留意 ./configure
那一步,Qt 会检测相关的环境及依赖库。
Building Qt 5 from Git
https://doc.qt.io/qt-6/linux-requirements.html
https://doc.qt.io/qt-5.15/linux-building.html
https://blog.csdn.net/luoyayun361/article/details/118395262
https://github.com/libjpeg-turbo/libjpeg-turbo/issues/547
https://blog.csdn.net/console_log/article/details/122881398
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。