ubuntu18.04编译qt5.14.2源码
文章目录
- ubuntu18.04编译qt5.14.2源码
-
- @[toc]
- 1 前言
- 2 参考文档
- 3 下载源码
-
- 4 ubuntu编译qt源码
-
- 5 help
-
- 6 问题记录
-
- 6.1 `WARNING: QDoc will not be compiled,`
- 6.2 `WARNING: QtWebEngine will not be built.`
- 6.3 `Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.`
- 6.4 `Project ERROR: Building QtQml requires Python.`
- 6.5 `class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)>`
- 6.6 内存不足`No space left on device`
- 6.7 `error: ‘runtime_error’ is not a member of ‘std’`
- 6.8 `error: ‘int32_t’ was not declared in this scope`
- 6.9 `Project ERROR: Missing archive files from QtWebEngineCore linking pri`
- 6.10 `WARNING: Static builds of QtWebEngine are not supported.`
- 6.11 编译帮助文档报错`Error parsing JSON at 1:1: illegal value`
- 6.12 `ninja: build stopped: subcommand failed.`
- 6.13 `error: xpath_grammar. hh: No such file or directory`
- 6.14 缺少ninja报错
- 6.15 `style.SortIncludes = false;`
- 6.16 ubuntu22.04编译qtwebengine后无法打开html
- 6.17 `undefined reference to pthread_create`
文章目录
- ubuntu18.04编译qt5.14.2源码
-
- @[toc]
- 1 前言
- 2 参考文档
- 3 下载源码
- 4 ubuntu编译qt源码
- 5 help
- 6 问题记录
-
- 6.1 `WARNING: QDoc will not be compiled,`
- 6.2 `WARNING: QtWebEngine will not be built.`
- 6.3 `Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.`
- 6.4 `Project ERROR: Building QtQml requires Python.`
- 6.5 `class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)>`
- 6.6 内存不足`No space left on device`
- 6.7 `error: ‘runtime_error’ is not a member of ‘std’`
- 6.8 `error: ‘int32_t’ was not declared in this scope`
- 6.9 `Project ERROR: Missing archive files from QtWebEngineCore linking pri`
- 6.10 `WARNING: Static builds of QtWebEngine are not supported.`
- 6.11 编译帮助文档报错`Error parsing JSON at 1:1: illegal value`
- 6.12 `ninja: build stopped: subcommand failed.`
- 6.13 `error: xpath_grammar. hh: No such file or directory`
- 6.14 缺少ninja报错
- 6.15 `style.SortIncludes = false;`
- 6.16 ubuntu22.04编译qtwebengine后无法打开html
- 6.17 `undefined reference to pthread_create`
更多精彩内容 |
---|
👉内容导航 👈 |
👉Qt开发经验 👈 |
👉Qt 👈 |
1 前言
本文演示了在ubuntu中编译Qt5.14.2源码,包含了Qt库、Qt帮助文档、QtWebEngine、qtcreator等,支持动态编译、静态编译;
编译Qt源码最重要的是需要看支持环境;
- 第一步:系统是否支持,不支持的系统也可以编译,不过编译过程中会出现各种问题,解决起来很复杂,例如在ubuntu22.04中编译Qt5.14.2就可以编译,但是问题很多;
- 第二步:编译器、构建工具、依赖库版本是否支持,最好选择推荐版本或者相差不大版本,否则肯定出问题,并且官方文档说的版本不一定可靠,有些版本不能按qt官方文档来;
- 第三步:新手不要编译QtWebEngine,编译时间长、硬件要求高、问题多;
- 第四步:先完成动态编译再考虑静态编译,静态编译问题比动态编译多;
- 满足了这几步后,基本上90%问题就没有了。
2 参考文档
系统版本:
构建Qt源码:
Qt构建选项:
构建Qtcreator:
构建Qt帮助文档:
构建QtWebEngine:
clang下载:
3 下载源码
3.1 方法1
- 进入github下载;
- 或者使用
git clone https://github.com/qt/qt5.git
或者git clone https://code.qt.io/qt/qt5.git
下载; - 然后使用
git tags
查看版本; - 使用
git checkout v5.14.2
切换版本; - 使用
perl init-repository
下载子仓库,或者使用git submodule update --init --recursive
;
3.2 方法2
进入Index of /official_releases/qt下载新版本qt源码;
或者进入Index of /archive/qt下载旧版本qt源码;
不过国内被屏蔽了,可能无法访问;
如下所示,下载源码;
3.3 方法3
安装Qt时勾选source;
然后进入Qt安装路径下,src文件夹内就是源码。
4 ubuntu编译qt源码
环境 | 说明 |
---|---|
系统 | ubuntu18.04(推荐)、ubuntu22.04 |
qt源码 | 5.14.2 |
g++ | >=7(注意:如果编译QtWebEngine使用11以上版本编译会失败) |
git | >=1.6 |
perl | >=5.14 |
python | >=2.6 |
clang | >=8 |
- 注意:使用ubuntu22.04编译Qt源码正常,但是编译QtWebEngine后无法加载html,并且编译源码过程中报错比较多。
4.1 环境准备
# 高版本系统需要将python改成python2,将g++改为g++-7或者g++-9
sudo apt-get install build-essential perl python3 python git g++
sudo ln /usr/bin/python2 /usr/bin/python # 将python2创建链接为python,防止找不到
# Libxcb 的
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
# Qt WebKit(Qt WebKit)
sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
# Qt Web引擎
sudo apt-get 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 flex
#Qt多媒体
sudo apt-get install libasound2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev
# QDoc文档生成(注意版本)
sudo apt install clang libclang-dev
#或者指定使用-9版本
sudo apt install clang-9 libclang-9-dev
# 完整依赖
sudo apt install libfontconfig1-dev libfreetype6-dev libx11-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxkbcommon-dev libxkbcommon-x11-dev libatspi2.0-dev
4.2 设置交换分区大小
当多线程编译时,内存和交换分区消耗会很大,以16线程编译为例子,26G略显不足;
当内存不足是,容易导致ninja报错。
在 Ubuntu 上设置 swap(交换分区/交换文件)大小,可以按照以下步骤操作:
查看当前 swap 情况
swapon --show free -h
关闭并删除现有 swap(如果需要调整大小)
sudo swapoff -a sudo rm /swapfile
创建新的 swap 文件(以 4G 为例)
sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
设置开机自动挂载:编辑
/etc/fstab
文件,添加如下内容(如果已存在则修改):/swapfile none swap sw 0 0
再次确认 swap
swapon --show free -h
可选:调整 swappiness(影响 swap 使用频率)
sudo sysctl vm.swappiness=10
如果设置
sudo swapon /swapfile
时报错:swapon: /swapfile: read swap header failed
则从头再设置。
4.3 编译源码
mkdir build
cd build
export LLVM_INSTALL_DIR=/usr/lib/llvm-9 # 设置llvm环境变量(临时),也可以加入.bashrc文件
# 编译静态库(不编译QtWebEngine)
../configure -developer-build -opensource -nomake examples -nomake tests -skip qtwebengine --prefix=/opt/qt5.14.2/ -static -release -force-debug-info -separate-debug-info
# 编译动态库(不编译QtWebEngine)
../configure -developer-build -opensource -nomake examples -nomake tests -skip qtwebengine --prefix=/opt/qt5.14.2/ -release -force-debug-info -separate-debug-info
# 编译动态库(编译QtWebEngine)
../configure -developer-build -opensource -nomake examples -nomake tests --prefix=/opt/qt5.14.2/ -release -force-debug-info -separate-debug-info
#加速编译,如果ninja报错了就改成-j1显示错误信息
export NINJAJOBS="-j8"
make -j8
make install
4.4 添加环境变量
export PATH="/opt/qt5.14.2/bin:$PATH"
export LD_LIBRARY_PATH="/opt/qt5.14.2/lib:$LD_LIBRARY_PATH"
4.5 验证编译结果
准备一个Qt程序源码;
test.pro
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 SOURCES += main.cpp
main.cpp
#include <QApplication> #include <QWidget> int main(int argc, char* argv[]) { QApplication a(argc, argv); QWidget w; w.show(); return a.exec(); }
运行
/opt/qt5.14.2/bin/qmake Test.pro
命令生成Makefile文件;运行
make
编译;运行
./Test
运行程序;使用
ldd ./Test
查看可执行程序依赖,如下图所示依赖中没有Qt库,证明静态编译成功;如下图所示:QtWebEngine编译运行成功,演示代码
4.6 编译帮助文档(qch)
编译前提:
- 查看构建要求:构建 Qt 文档 - Qt Wiki
- Qt源码构建完成,并且构建了qttools子工程;
- 使用
ls /opt/qt5.14.2/bin
查看编译后成功生成了qdoc
可执行程序;
构建命令:
# 进入qt源码路径 mkdir build cd build # 不是必要,如果报错,则更具报错信息使用-skip跳过对应子工程 ../configure -opensource -make libs -skip qtwebengine -skip qttools -skip qtdeclarative --prefix=/opt/qt5.14.2/ make docs make install_docs
编译成功后如下所示:
4.7 编译QtCreator
编译前提:
- github下载源码
- 或者Index of /archive/qtcreator、Index of /official_releases/qtcreator下载源码;
- 然后查看源码中的README.md中的编译说明;
- 注意:如果编译Qt源码时没有编译QtWebEngine则无法编译QtCreator;
- 使用
sudo apt install cmake cmake-gui
安装cmake; - 由于ubuntu中apt安装默认最高只有10,而使用clang10以下版本会报错;
- 进入github下载clang+llvm-11.1.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
- 解压到本地;
开始编译:
将qtcreator源码中的CMakeLists.txt拖进cmake中,点击【Configure】,选择Makefile;
将
Clang-DIR
、LLVM_DIR
设置为解压的clang路径;
- 修改
CMAKE_INSTALL_PREFIX
设置安装路径; - 点击【Configure】【Generate】;
- 然后打开终端进入qtcreator/build路径;
- 运行
make
、make install
; - 打开
.bashrc
,添加环境变量;
export PATH="/opt/qtcreator/bin:$PATH" export LD_LIBRARY_PATH="/opt/qtcreator/lib:$LD_LIBRARY_PATH"
验证结果;
- 编译完成后进入bin文件夹;
- 运行
./qtcreator
;
5 help
用法: configure [options] [assignments]
Configure 支持在命令行中像 VAR=value 这样的变量赋值。每个大写的库名(可通过 -list-libraries 获取)支持后缀 _INCDIR、_LIBDIR、_PREFIX(INCDIR=PREFIX/include, LIBDIR=PREFIX/lib)、_LIBS,以及在 Windows 和 Darwin 上的 _LIBS_DEBUG 和 _LIBS_RELEASE。例如:
ICU_PREFIX=/opt/icu42 ICU_LIBS=“-licui18n -licuuc -licudata”。也可以操作任何 QMAKE_* 变量,以修正 mkspec 中 Qt 自身构建的值,例如:QMAKE_CXXFLAGS+=-g3。
注意,_LIBS 和 QMAKE_* 赋值操作的是列表,因此包含元字符(尤其是空格)的项需要按照 qmake 规则加引号。此外,整个赋值还需要按照 shell 规则加引号。推荐内部使用单引号,外部使用双引号。
5.1 顶层安装目录
选项 | 说明 |
---|---|
-prefix <dir> |
部署目录,目标设备可见。默认:/usr/local/Qt-$QT_VERSION ;如果使用 -developer-build ,则为 qtbase 构建目录 |
-extprefix <dir> |
主机可见的安装目录。默认:SYSROOT/PREFIX |
-hostprefix [dir] |
构建工具在主机上的安装目录。如果未指定 [dir],则使用当前构建目录。默认:EXTPREFIX |
-external-hostbindir <path> |
针对本机构建的 Qt 工具路径。当 -platform 与当前系统不符时使用,例如 Canadian Cross Build。 |
5.2 安装目录布局微调
- (除
-sysconfdir
外,所有目录应位于-prefix
/-hostprefix
下)
选项 | 说明 |
---|---|
-bindir <dir> |
可执行文件目录,默认:PREFIX/bin |
-headerdir <dir> |
头文件目录,默认:PREFIX/include |
-libdir <dir> |
库文件目录,默认:PREFIX/lib |
-archdatadir <dir> |
架构相关数据目录,默认:PREFIX |
-plugindir <dir> |
插件目录,默认:ARCHDATADIR/plugins |
-libexecdir <dir> |
辅助程序目录,Windows 默认:ARCHDATADIR/bin ,其他平台:ARCHDATADIR/libexec |
-importdir <dir> |
QML1 导入目录,默认:ARCHDATADIR/imports |
-qmldir <dir> |
QML2 导入目录,默认:ARCHDATADIR/qml |
-datadir <dir> |
架构无关数据目录,默认:PREFIX |
-docdir <dir> |
文档目录,默认:DATADIR/doc |
-translationdir <dir> |
翻译文件目录,默认:DATADIR/translations |
-sysconfdir <dir> |
Qt 程序使用的设置目录,默认:PREFIX/etc/xdg |
-examplesdir <dir> |
示例目录,默认:PREFIX/examples |
-testsdir <dir> |
测试目录,默认:PREFIX/tests |
-hostbindir <dir> |
主机可执行文件目录,默认:HOSTPREFIX/bin |
-hostlibdir <dir> |
主机库文件目录,默认:HOSTPREFIX/lib |
-hostdatadir <dir> |
qmake 使用的数据目录,默认:HOSTPREFIX |
其余选项的约定:当选项说明后跟有值列表时,含义如下:
yes
表示仅有该选项;其他值为该选项的可能前缀,例如-no-gui
。- 也可以赋值,如
--gui=yes
。 - 值按未指定时的尝试顺序排列;
auto
是yes/no
的简写。 - 单独的
yes
和no
表示无自动检测的二元选项。
5.3 Configure 元选项
选项 | 说明 |
---|---|
-help, -h |
显示此帮助信息 |
-verbose, -v |
配置期间输出详细信息 |
-continue |
配置出错时继续 |
-redo |
使用之前的选项重新配置。可传递额外选项,但不会被 -redo 记录 |
-recheck [test,...] |
清除缓存的失败配置测试结果。安装缺失依赖后使用。指定测试时,仅清除指定测试结果 |
-recheck-all |
清除所有缓存的配置测试结果 |
-feature-<feature> |
启用 <feature> 功能 |
-no-feature-<feature> |
禁用 <feature> 功能 |
-list-features |
列出可用功能。部分功能有专用命令行选项 |
-list-libraries |
列出可能的外部依赖库 |
5.4 构建选项
选项 | 说明 |
---|---|
-opensource |
构建 Qt 开源版 |
-commercial |
构建 Qt 商业版 |
-confirm-license |
自动接受许可协议 |
-release |
构建关闭调试的 Qt(默认) |
-debug |
构建开启调试的 Qt |
-debug-and-release |
同时构建带调试和不带调试的 Qt(仅 Apple 和 Windows) |
-optimize-debug |
在调试构建中启用优化(不支持 MSVC 或 Clang) |
-optimize-size |
优化发布构建以减小体积 |
-optimized-tools |
即使在调试构建中也构建优化的主机工具 |
-force-debug-info |
为发布构建生成符号文件 |
-separate-debug-info |
将调试信息分离到独立文件 |
-gdb-index |
为 GDB 加速索引调试信息 |
-strip |
移除发布二进制文件中不需要的符号 |
-gc-binaries |
每个函数或数据项单独分区,启用链接器垃圾回收 |
-force-asserts |
即使在发布构建中也启用 Q_ASSERT |
-developer-build |
为 Qt 自身开发编译和链接 Qt(导出自动测试、额外检查等) |
-shared |
构建共享 Qt 库(默认,UIKit 除外) |
-static |
构建静态 Qt 库(UIKit 默认) |
-framework |
构建 Qt 框架包(仅 Apple) |
-platform <target> |
选择主机 mkspec(默认自动检测) |
-xplatform <target> |
交叉编译时选择目标 mkspec |
-device <name> |
为指定设备交叉编译 |
-device-option <key=value> |
为设备 mkspec 添加选项 |
-appstore-compliant |
禁用不允许在平台应用商店分发的代码(部分平台默认开启) |
-qtnamespace <name> |
将所有 Qt 库代码包裹在 namespace <name> {...} 中 |
-qtlibinfix <infix> |
将所有 libQt5*.so 重命名为 libQt5*.so |
-qtlibinfix-plugins |
按 -qtlibinfix 重命名 Qt 插件 |
-testcocoon |
使用 TestCocoon 代码覆盖工具 |
-gcov |
使用 GCov 代码覆盖工具 |
-trace [backend] |
启用 tracepoints,支持 ‘etw’(Windows)、‘lttng’(Linux)或 ‘yes’ 自动检测 |
-sanitize |
thread |
-coverage {trace-pc-guard} |
添加代码覆盖率插桩(仅 Clang) |
-c++std <edition> |
选择 C++ 标准版本(不支持 MSVC 2015) |
-sse2 |
使用 SSE2 指令集 |
-sse3/-ssse3/-sse4.1/-sse4.2/-avx/-avx2/-avx512 |
启用特定 x86 指令集 |
-mips_dsp/-mips_dspr2 |
使用 MIPS DSP/rev2 指令集 |
-qreal <type> |
将 qreal typedef 为指定类型(影响二进制兼容性) |
-R <string> |
为 Qt 库添加运行时库路径,支持相对 LIBDIR 的路径 |
-rpath |
使用库安装路径作为运行时库路径链接 Qt 库和可执行文件 |
-reduce-exports |
减少导出符号数量 |
-reduce-relocations |
减少重定位数量(仅 Unix) |
-plugin-manifests |
将清单嵌入插件(仅 Windows) |
-static-runtime |
静态链接时使用静态运行库(仅 Windows) |
-pch |
使用预编译头文件 |
-ltcg |
启用链接时代码生成 |
-linker [bfd,gold,lld] |
强制使用指定的 GNU ld、gold 或 LLVM/LLD 链接器(仅 GCC) |
-incredibuild-xge |
使用 IncrediBuild XGE(仅 Windows) |
-ccache |
使用 ccache 编译器缓存(仅 Unix) |
-make-tool <tool> |
使用指定工具构建 qmake(仅 Windows,默认 nmake) |
-mp |
多处理器并行编译(仅 MSVC) |
-warnings-are-errors |
将警告视为错误(-developer-build 时默认开启) |
-silent |
减少构建输出,便于查看警告和错误 |
5.5 构建环境
选项 | 说明 |
---|---|
-sysroot <dir> |
设置目标 sysroot 目录 |
-gcc-sysroot |
配合 -sysroot ,向编译器传递 --sysroot (默认开启) |
-pkg-config |
使用 pkg-config(仅 Unix,默认自动) |
-D <string> |
传递额外的预处理器定义 |
-I <string> |
传递额外的头文件包含路径 |
-L <string> |
传递额外的库文件路径 |
-F <string> |
传递额外的 framework 路径(仅 Apple) |
-sdk <sdk> |
使用指定 Apple SDK 构建 Qt,参数为 xcodebuild -showsdks 列出的 SDK |
-android-sdk path |
设置 Android SDK 根路径 |
-android-ndk path |
设置 Android NDK 根路径 |
-android-ndk-platform |
设置 Android 平台 |
-android-ndk-host |
设置 Android NDK 主机(如 linux-x86, linux-x86_64 等) |
-android-abis |
逗号分隔的 Android abi,默认:armeabi-v7a,arm64-v8a,x86,x86_64 |
-android-style-assets |
运行时自动提取样式资源,使 Android 样式正确,但与 LGPL2.1 不兼容 |
5.6 组件选择
选项 | 说明 |
---|---|
-skip <repo> |
排除整个仓库的构建 |
-make <part> |
添加构建部分,指定后会清空默认列表(默认构建 libs、examples,非交叉编译时还包括 tools,-developer-build 时还包括 tests) |
-nomake <part> |
排除指定部分的构建 |
-compile-examples |
未设置时仅安装示例源码(WebAssembly 默认否,其他默认是) |
-gui |
构建 Qt GUI 模块及依赖(默认开启) |
-widgets |
构建 Qt Widgets 模块及依赖(默认开启) |
-no-dbus |
不构建 Qt D-Bus 模块(Android 和 Windows 默认) |
-dbus-linked |
构建 Qt D-Bus 并链接 libdbus-1(默认自动) |
-dbus-runtime |
构建 Qt D-Bus 并动态加载 libdbus-1(默认否) |
-accessibility |
启用辅助功能支持(默认开启,建议不要禁用) |
Qt 自带部分第三方库的捆绑副本。若自动检测系统库失败,则默认使用这些副本。
5.7 核心选项
选项 | 说明 |
---|---|
-doubleconversion |
选择 double conversion 库(system/qt/no) |
-glib |
启用 Glib 支持(Unix 默认自动) |
-eventfd |
启用 eventfd 支持 |
-inotify |
启用 inotify 支持 |
-iconv |
启用 iconv(3) 支持(posix/sun/gnu/no,仅 Unix) |
-icu |
启用 ICU 支持 |
-pcre |
选择 libpcre2(system/qt/no) |
-pps |
启用 PPS 支持(仅 QNX) |
-zlib |
选择 zlib(system/qt) |
5.8 日志后端
选项 | 说明 |
---|---|
-journald |
启用 journald 支持(仅 Unix) |
-syslog |
启用 syslog 支持(仅 Unix) |
-slog2 |
启用 slog2 支持(仅 QNX) |
5.9 网络选项
选项 | 说明 |
---|---|
-ssl |
启用 SSL 支持(默认自动) |
-no-openssl |
不使用 OpenSSL(Apple 和 WinRT 默认) |
-openssl-linked |
使用 OpenSSL 并链接 libssl |
-openssl-runtime |
使用 OpenSSL 并动态加载 libssl |
-schannel |
使用 Secure Channel(仅 Windows) |
-securetransport |
使用 SecureTransport(仅 Apple) |
-sctp |
启用 SCTP 支持 |
-libproxy |
启用 libproxy 支持 |
-system-proxies |
默认使用系统网络代理 |
5.10 图形、打印、控件选项
选项 | 说明 |
---|---|
-cups |
启用 CUPS 支持(仅 Unix) |
-fontconfig |
启用 Fontconfig 支持(仅 Unix) |
-freetype |
选择 FreeType(system/qt/no) |
-harfbuzz |
选择 HarfBuzz-NG(system/qt/no,Apple 和 Windows 不自动检测) |
-gtk |
启用 GTK 平台主题支持 |
-lgmon |
启用 lgmon 支持(仅 QNX) |
-no-opengl |
禁用 OpenGL 支持 |
-opengl <api> |
启用 OpenGL 支持,支持 es2(Windows 默认)、desktop(Unix 默认)、dynamic(仅 Windows) |
-opengles3 |
启用 OpenGL ES 3.x 支持 |
-egl |
启用 EGL 支持 |
-angle |
使用捆绑的 ANGLE 支持 OpenGL ES 2.0(仅 Windows) |
-combined-angle-lib |
合并 LibEGL 和 LibGLESv2 为 LibANGLE(仅 Windows) |
-qpa <name> |
选择默认 QPA 后端(如 xcb, cocoa, windows),用分号分隔优先级 |
-xcb-xlib |
启用 Xcb-Xlib 支持 |
5.11 平台后端
选项 | 说明 |
---|---|
-direct2d |
启用 Direct2D 支持(仅 Windows) |
-directfb |
启用 DirectFB 支持(仅 Unix) |
-eglfs |
启用 EGLFS 支持(Android 和 Windows 默认否) |
-gbm |
启用 GBM 后端(仅 Linux) |
-kms |
启用 KMS 后端(仅 Linux) |
-linuxfb |
启用 Linux Framebuffer 支持(仅 Linux) |
-xcb |
启用 X11 支持,选择 xcb-* 库(system/qt/no) |
5.12 输入后端
选项 | 说明 |
---|---|
-libudev |
启用 udev 支持 |
-evdev |
启用 evdev 支持 |
-imf |
启用 IMF 支持(仅 QNX) |
-libinput |
启用 libinput 支持 |
-mtdev |
启用 mtdev 支持 |
-tslib |
启用 tslib 支持 |
-xcb-xinput |
启用 XInput2 支持 |
-xkbcommon |
启用按键映射支持 |
5.13 图像格式
选项 | 说明 |
---|---|
-gif |
启用 GIF 读取支持 |
-ico |
启用 ICO 支持 |
-libpng |
选择 libpng(system/qt/no) |
-libjpeg |
选择 libjpeg(system/qt/no) |
5.14 数据库选项
选项 | 说明 |
---|---|
-sql-<driver> |
启用 SQL <driver> 插件,支持 db2 ibase mysql oci odbc psql sqlite2 sqlite tds |
-sqlite |
选择 sqlite3(system/qt) |
5.15 Qt3D 选项
选项 | 说明 |
---|---|
-assimp |
选择 assimp 库(system/qt/no) |
-qt3d-profile-jobs |
启用 jobs profiling |
-qt3d-profile-gl |
启用 OpenGL profiling |
-qt3d-simd |
选择 SIMD 支持级别(no/sse2/avx2) |
-qt3d-render |
启用 Qt3D Render 组件 |
-qt3d-input |
启用 Qt3D Input 组件 |
-qt3d-logic |
启用 Qt3D Logic 组件 |
-qt3d-extras |
启用 Qt3D Extras 组件 |
-qt3d-animation |
启用 Qt3D Animation 组件 |
5.16 其他图像格式选项
选项 | 说明 |
---|---|
-jasper |
启用 JasPer 库的 JPEG-2000 支持 |
-mng |
启用 MNG 支持 |
-tiff |
启用 TIFF 支持(system/qt/no) |
-webp |
启用 WEBP 支持(system/qt/no) |
5.17 多媒体选项
选项 | 说明 |
---|---|
-pulseaudio |
启用 PulseAudio 支持(仅 Unix) |
-alsa |
启用 ALSA 支持(仅 Unix) |
-no-gstreamer |
禁用 GStreamer 支持 |
-gstreamer [version] |
启用 GStreamer 支持,未指定参数时优先尝试 1.0,再尝试 0.10 |
-evr |
在 DirectShow 和 WMF 中启用 EVR |
5.18 QtQuick3D 选项
选项 | 说明 |
---|---|
-assimp |
选择 assimp 库(system/qt/no) |
5.19 TextToSpeech 选项
选项 | 说明 |
---|---|
-flite |
启用 Flite 支持(仅 Unix) |
-flite-alsa |
启用 Flite 的 ALSA 支持(仅 Unix) |
-speechd |
启用 speech dispatcher 支持(仅 Unix) |
5.20 WebEngine 选项
选项 | 说明 |
---|---|
-webengine-alsa |
启用 ALSA 支持(仅 Linux) |
-webengine-pulseaudio |
启用 PulseAudio 支持(仅 Linux) |
-webengine-embedded-build |
启用 Linux 嵌入式构建(仅 Linux) |
-webengine-icu |
使用系统 ICU 库(仅 Linux) |
-webengine-ffmpeg |
使用系统 FFmpeg 库(仅 Linux) |
-webengine-opus |
使用系统 Opus 库(仅 Linux) |
-webengine-webp |
使用系统 WebP 库(仅 Linux) |
-webengine-pepper-plugins |
启用 Pepper Flash 和 Widevine 插件支持 |
-webengine-printing-and-pdf |
启用打印和 PDF 输出支持 |
-webengine-proprietary-codecs |
启用专有编解码器支持 |
-webengine-spellchecker |
启用拼写检查支持 |
-webengine-native-spellchecker |
启用原生拼写检查支持(仅 macOS) |
-webengine-webrtc |
启用 WebRTC 支持 |
6 问题记录
6.1 WARNING: QDoc will not be compiled,
报错信息:
WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
问题原因:找不到libclang路径
解决办法:
- 使用
sudo apt install clang libclang-dev
安装libclang; - 在运行…/configure构建命令前,使用
export LLVM_INSTALL_DIR=/usr/lib/llvm-14
命令添加环境变量,可以先使用ls /usr/lib/llvm*
命令查看路径下是否有llvm安装目录。
- 使用
6.2 WARNING: QtWebEngine will not be built.
报错信息:
Note: The following modules are not being compiled in this configuration: webenginecore webengine webenginewidgets WARNING: Tool flex is required to build QtWebEngine. WARNING: Python version 2 (2.7.5 or later) is required to build QtWebEngine. WARNING: QtWebEngine will not be built. WARNING: QtPdf will not be built.
问题原因:缺少
flex
依赖;解决办法:使用
sudo apt install flex python2
安装依赖;
6.3 Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.
报错信息:
Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.
问题原因:缺少
libdbus-1-dev
或者libatspi2.0-dev
;解决办法:使用命令
sudo apt install libdbus-1-dev libatspi2.0-dev
安装依赖,如果不存在,就使用sudo apt install libatspi
命令,按Tab键查看可安装的版本;
6.4 Project ERROR: Building QtQml requires Python.
报错信息:执行make、make install后报错如下
sh: 1: python: not found Project ERROR: Building QtQml requires Python. make: *** [Makefile:352: module-qtdeclarative-install_subtargets] Error 3
问题原因:编译QtQml找不到python;
解决办法:
- 使用
sudo apt install python
或者sudo apt install python2
安装; - 安装后使用
python --version
或者python2 --version
看是否安装成功; - 如果
python --version
无法显示版本,而python2 --version
可以显示版本; - 则使用
sudo ln /usr/bin/python2 /usr/bin/python
创建链接;
- 使用
6.5 class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)>
报错信息:执行make时报错如下
class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float> 5.14.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:295:7: error: ‘numeric_limits’ is not a class template 295 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float> | ^~~~~~~~~~~~~~
解决办法:打开
qtbase/src/corelib/global/qglobal.h
,添加#include <limits>
;#ifdef __cplusplus # include <type_traits> # include <cstddef> # include <utility> # include <limits> #endif
6.6 内存不足No space left on device
报错信息:执行make编译到一半报错如下
cannot write PCH file: No space left on device
问题原因:系统内存不足。
6.7 error: ‘runtime_error’ is not a member of ‘std’
报错信息:执行make install时报错如下
/home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp: In member function ‘void mbgl::BiDi::mergeParagraphLineBreaks(std::set<long unsigned int>&)’: /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp:63:24: error: ‘runtime_error’ is not a member of ‘std’ 63 | throw std::runtime_error(std::string("ProcessedBiDiText::mergeParagraphLineBreaks: ") + | ^~~~~~~~~~~~~ /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp: In member function ‘std::vector<std::__cxx11::basic_string<char16_t> > mbgl::BiDi::processText(const u16string&, std::set<long unsigned int>)’: /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp:98:20: error: ‘runtime_error’ is not a member of ‘std’ 98 | throw std::runtime_error(std::string("BiDi::processText: ") + u_errorName(errorCode)); | ^~~~~~~~~~~~~ /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp: In member function ‘std::u16string mbgl::BiDi::getLine(std::size_t, std::size_t)’: /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp:109:20: error: ‘runtime_error’ is not a member of ‘std’ 109 | throw std::runtime_error(std::string("BiDi::getLine (setLine): ") + u_errorName(errorCode)); | ^~~~~~~~~~~~~ /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/platform/default/bidi.cpp:125:20: error: ‘runtime_error’ is not a member of ‘std’ 125 | throw std::runtime_error(std::string("BiDi::getLine (writeReordered): ") + | ^~~~~~~~~~~~~ make[5]: *** [Makefile:3883: .obj/platform/default/bidi. o] Error 1 make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/3rdparty/mapbox-gl-native' make[4]: *** [Makefile:215: sub-------3rdparty-mapbox-gl-native-install_subtargets] Error 2 make[4]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/plugins/geoservices' make[3]: *** [Makefile:85: sub-geoservices-install_subtargets] Error 2 make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/plugins' make[2]: *** [Makefile:248: sub-plugins-install_subtargets] Error 2 make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src' make[1]: *** [Makefile:61: sub-src-install_subtargets] Error 2 make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation' make: *** [Makefile:828: module-qtlocation-install_subtargets] Error 2
问题原因:缺少
stdexcept
头文件;解决办法:打开报错的文件,添加
#include <stdexcept>
6.8 error: ‘int32_t’ was not declared in this scope
报错信息:执行make install时报错如下
/home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/util/convert.cpp:6:56: error: ‘int32_t’ was not declared in this scope 6 | template std::array<float, 2> convert(const std::array<int32_t, 2>&); | ^~~~~~~ /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/util/convert.cpp:2:1: note: ‘int32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? 1 | #include <mbgl/util/convert.hpp> +++ |+#include <cstdint> 2 | /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/util/convert.cpp:6:66: error: template argument 1 is invalid 6 | template std::array<float, 2> convert(const std::array<int32_t, 2>&); | ^ /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/util/convert.cpp:6:31: error: template-id ‘convert<>’ for ‘std::array<float, 2> mbgl::util::convert(const int&)’ does not match any template declaration 6 | template std::array<float, 2> convert(const std::array<int32_t, 2>&); | ^~~~~~~ In file included from /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/util/convert.cpp:1: /home/mhf/Code/qt-everywhere-src-5.14.2/qtlocation/src/3rdparty/mapbox-gl-native/include/mbgl/util/convert.hpp:12:37: note: candidate is: ‘template<class To, class From, long unsigned int Size, class> constexpr std::array<To, Size> mbgl::util::convert(const std::array<_Tp, _Nm>&)’ 12 | MBGL_CONSTEXPR std::array<To, Size> convert(const std::array<From, Size>&from) { | ^~~~~~~ make[5]: *** [Makefile:59975: .obj/src/mbgl/util/convert.o] Error 1 make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/3rdparty/mapbox-gl-native' make[4]: *** [Makefile:215: sub-------3rdparty-mapbox-gl-native-install_subtargets] Error 2 make[4]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/plugins/geoservices' make[3]: *** [Makefile:85: sub-geoservices-install_subtargets] Error 2 make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src/plugins' make[2]: *** [Makefile:248: sub-plugins-install_subtargets] Error 2 make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation/src' make[1]: *** [Makefile:61: sub-src-install_subtargets] Error 2 make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtlocation' make: *** [Makefile:828: module-qtlocation-install_subtargets] Error 2
问题原因:编译器无法识别
int32_t
类型;解决办法:打开报错文件,包含头文件 int32_t 是 C/C++ 标准库中定义的类型,需要添加头文件:
#include <cstdint> // C++ 标准用法 // 或 #include <stdint.h> // C 风格头文件(兼容性更好)
6.9 Project ERROR: Missing archive files from QtWebEngineCore linking pri
报错信息:执行make编译时报错如下
Project ERROR: Missing archive files from QtWebEngineCore linking pri make[3]: *** [Makefile:132: sub-core_module-pro-install_subtargets] Error 3 make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core' make[2]: *** [Makefile:90: sub-core-install_subtargets] Error 2 make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src' make[1]: *** [Makefile:61: sub-src-install_subtargets] Error 2 make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine' make: *** [Makefile:1100: module-qtwebengine-install_subtargets] Error 2
问题原因:不支持静态编译QtWebengine;
解决办法:configure构建时加上
-skip qtwebengine
;
6.10 WARNING: Static builds of QtWebEngine are not supported.
报错信息:执行configure构建后报错如下
Note: The following modules are not being compiled in this configuration: webenginecore webengine webenginewidgets WARNING: Static builds of QtWebEngine are not supported. WARNING: QtWebEngine will not be built. WARNING: QtPdf will not be built. Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into '/opt/qt5.14.2'. Prior to reconfiguration, make sure you remove any leftovers from the previous build.
问题原因:不支持静态编译QtWebengine;
解决办法:configure构建时加上
-skip qtwebengine
;
6.11 编译帮助文档报错Error parsing JSON at 1:1: illegal value
报错信息:执行make docs编译时报错如下
make[5]: Entering directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmlpreview' make[5]: Nothing to be done for 'prepare_docs'. make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmlpreview' make[5]: Entering directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmllint' make[5]: Nothing to be done for 'prepare_docs'. make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmllint' make[5]: Entering directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmlcachegen' make[5]: Nothing to be done for 'prepare_docs'. make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmlcachegen' make[5]: Entering directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmltestrunner' make[5]: Nothing to be done for 'prepare_docs'. make[5]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qmltestrunner' /home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools/qml/qmlimportscanner_wrapper.sh: 6: exec: /home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/bin/qmlimportscanner: not found /home/mhf/Code/qt-everywhere-src-5.14.2/qtbase/mkspecs/features/qt.prf:285: Error parsing JSON at 1:1: illegal value Project ERROR: Failed to parse qmlimportscanner output. make[4]: *** [Makefile:1007: sub-qml-prepare_docs] Error 3 make[4]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative/tools' make[3]: *** [Makefile:643: sub-tools-prepare_docs] Error 2 make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtdeclarative' make[2]: *** [Makefile:2909: module-qtdeclarative-prepare_docs] Error 2 make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build' make[1]: *** [Makefile:2060: html_docs] Error 2 make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build' make: *** [Makefile:2063: docs] Error 2
问题原因:
qtdeclarative
子工程无法生成qch文档;解决办法:使用configure构建时加上
-skip qtdeclarative
,如果报错的是其它子工程,就在-skip
后改为对应的子工程就可以。
6.12 ninja: build stopped: subcommand failed.
- 报错信息:使用make编译QtWebengine时报错如下
ringssl/src/crypto/fipsmodule/bcm.c -o obj/third_party/boringssl/boringssl/bcm.o
ninja: build stopped: subcommand failed.
make[4]: *** [Makefile. gn_run:1263: run_ninja] Error 1
make[4]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core'
make[3]: *** [Makefile:82: sub-gn_run-pro-make_first] Error 2
make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core'
make[2]: *** [Makefile:78: sub-core-make_first] Error 2
make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src'
make[1]: *** [Makefile:49: sub-src-make_first] Error 2
make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine'
make: *** [Makefile:1088: module-qtwebengine-make_first] Error 2
问题原因:由于某种错误导致ninja构建失败;
解决办法:
默认情况下ninja构建失败可能看不到具体的错误信息;
在终端中输入
export NINJAJOBS="-j1"
,然后再执行make就会显示报错信息,例如;../../../../../qtwebengine/src/3rdparty/chromium/third_party/perfetto/include/perfetto/base/task_runner.h:48:55: error: ‘uint32_t’ has not been declared 48 | virtual void PostDelayedTask(std::function<void()>, uint32_t delay_ms) = 0; |
可能是内存不足、硬盘空间(18G)、交换分区不足;
编译时如果内存不足或者交换分区不足则减少编译的线程数,如下所示使用16线程编译,26G内存都略显不足;
- 解决办法1:将交换分区设置大一点;
- 解决办法2:将NiNJAJOBS设置小一点,减少编译线程数。
也可能是g++版本不支持,使用g+±11编译就会在编译到
qtwebengine/src/core
时报错,改为g+±9就正常了;使用
sudo apt install g++-9
安装;然后使用
sudo ln /usr/bin/g++-9 /usr/bin/g++
将g+±9创建别名;使用
g++ -v
命令检查版本;
6.13 error: xpath_grammar. hh: No such file or directory
- 报错信息:使用make编译qtwebengine时报错
/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core/release/gen/third_party/blink/renderer/core/xpath_grammar. cc:124:10: fatal error: xpath_grammar. hh: No such file or directory
124 | #include "xpath_grammar.hh"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
make[4]: *** [Makefile. gn_run:1263: run_ninja] Error 1
make[4]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core'
make[3]: *** [Makefile:82: sub-gn_run-pro-make_first] Error 2
make[3]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core'
make[2]: *** [Makefile:78: sub-core-make_first] Error 2
make[2]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src'
make[1]: *** [Makefile:49: sub-src-make_first] Error 2
make[1]: Leaving directory '/home/mhf/Code/qt-everywhere-src-5.14.2/build/qtwebengine'
make: *** [Makefile:1088: module-qtwebengine-make_first] Error 2
问题原因:似乎是由于bison版本过高导致
解决办法:
使用
sudo apt remove bison
卸载bison;编译安装bison3.1;
wget http://ftp.gnu.org/gnu/bison/bison-3.1.tar.gz tar -xzvf bison-3.1.tar.gz cd bison-3.1 ./configure make sudo make install
进入
/Code/qt-everywhere-src-5.14.2/build/qtwebengine/src/core/release/gen/third_party/blink/renderer/core
路径;使用
gedit xpath_grammar.cc
打开源文件;将
#include "xpath_grammar.hh
改为#include "xpath_grammar.h
;然后再次执行make编译。
6.14 缺少ninja报错
- 报错信息:使用make编译qtcreator报错
#warning ClangFormat: building against unmodified Clang, see README. md for more info
^
1 warning generated.
make[1]: *** [CMakeFiles/Makefile2:9240: src/plugins/clangformat/CMakeFiles/ClangFormat. dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 77%] Linking CXX shared library ../../../lib/qtcreator/plugins/libQbsProjectManager.so
[ 77%] Built target Debugger
[ 77%] Linking CXX shared library ../../../lib/qtcreator/plugins/libQmlJSEditor.so
[ 77%] Built target QbsProjectManager
[ 77%] Built target QmlJSEditor
make: *** [Makefile:136: all] Error 2
- 解决办法:使用
sudo apt install ninja-build
安装ninja;
6.15 style.SortIncludes = false;
- 报错信息:使用make编译qtcreator报错
/home/mhf/Code/qt-creator-opensource-src-4.15.2/src/plugins/clangformat/clangformatbaseindenter.cpp:45:26: error: assigning to 'clang::format::FormatStyle::SortIncludesOptions' from incompatible type 'bool'
style.SortIncludes = false;
^~~~~
1 error generated.
make[2]: *** [src/plugins/clangformat/CMakeFiles/ClangFormat.dir/build.make:94: src/plugins/clangformat/CMakeFiles/ClangFormat.dir/clangformatbaseindenter.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:9240: src/plugins/clangformat/CMakeFiles/ClangFormat.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
问题原因:由于clang版本不同,其中存在不兼容;
解决办法:
- qtcreator源码中README.md版本要求安装clang;
- 或者打开报错的文件,将false改为对应的枚举。
// style.SortIncludes = false; style.SortIncludes = clang::format::FormatStyle::SI_Never; //style.SortIncludes = true; style.SortIncludes = clang::format::FormatStyle::SI_CaseSensitive; // style.SpacesInAngles = false; style.SpacesInAngles = clang::format::FormatStyle::SIAS_Never;
6.16 ubuntu22.04编译qtwebengine后无法打开html
报错信息:在ubuntu22.04上编译的qtwebengine可以正常编译,但是运行后无法打开html
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. QSocketNotifier: Can only be used with threads started with QThread
6.17 undefined reference to pthread_create
报错信息:使用clang-10编译qtcreator4.15.2时报错
Determining if the pthread_create exist failed with the following output: Change Dir: /home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/make" "cmTC_c9727/fast" /usr/bin/make -f CMakeFiles/cmTC_c9727.dir/build. make CMakeFiles/cmTC_c9727.dir/build make[1]: Entering directory '/home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_c9727.dir/CheckSymbolExists.c.o /usr/bin/cc -o CMakeFiles/cmTC_c9727.dir/CheckSymbolExists.c. o -c /home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c Linking C executable cmTC_c9727 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c9727.dir/link.txt --verbose=1 /usr/bin/cc CMakeFiles/cmTC_c9727.dir/CheckSymbolExists.c. o -o cmTC_c9727 CMakeFiles/cmTC_c9727.dir/CheckSymbolExists.c. o: In function `main': CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create' collect2: error: ld returned 1 exit status CMakeFiles/cmTC_c9727.dir/build. make:97: recipe for target 'cmTC_c9727' failed make[1]: *** [cmTC_c9727] Error 1 make[1]: Leaving directory '/home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp' Makefile:126: recipe for target 'cmTC_c9727/fast' failed make: *** [cmTC_c9727/fast] Error 2 File /home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: /* */ #include <pthread.h> int main(int argc, char** argv) { (void)argv; #ifndef pthread_create return ((int*)(&pthread_create))[argc]; #else (void)argc; return 0; #endif } Determining if the function pthread_create exists in the pthreads failed with the following output: Change Dir: /home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/make" "cmTC_f3a0e/fast" /usr/bin/make -f CMakeFiles/cmTC_f3a0e.dir/build. make CMakeFiles/cmTC_f3a0e.dir/build make[1]: Entering directory '/home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_f3a0e.dir/CheckFunctionExists.c.o /usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_f3a0e.dir/CheckFunctionExists.c. o -c /usr/share/cmake-3.10/Modules/CheckFunctionExists.c Linking C executable cmTC_f3a0e /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_f3a0e.dir/link.txt --verbose=1 /usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_f3a0e.dir/CheckFunctionExists.c. o -o cmTC_f3a0e -lpthreads /usr/bin/ld: cannot find -lpthreads collect2: error: ld returned 1 exit status CMakeFiles/cmTC_f3a0e.dir/build. make:97: recipe for target 'cmTC_f3a0e' failed make[1]: *** [cmTC_f3a0e] Error 1 make[1]: Leaving directory '/home/mhf/Code/qt-creator-opensource-src-4.15.2/build/CMakeFiles/CMakeTmp' Makefile:126: recipe for target 'cmTC_f3a0e/fast' failed make: *** [cmTC_f3a0e/fast] Error 2
错误原因:clang10不兼容;
解决办法:下载clang11编译。