qt之库编译错误:src/client/qwayland-wayland.h: No such file or directory

本文介绍了解决Qt 5.15.3在构建过程中遇到的QWaylandDisplay_p.h文件错误,通过在configure阶段使用-skipwayland选项来避开Wayland模块编译问题,确保Qt项目的顺利构建。

错误描述

In file included from /root/workspace/qt-everywhere-src-5.15.3/qtwayland/src/client/qwaylanddisplay_p.h:64:0,
                 from /root/workspace/qt-everywhere-src-5.15.3/qtwayland/src/client/qwaylandintegration.cpp:42:
../../include/QtWaylandClient/5.15.3/QtWaylandClient/private/qwayland-wayland.                                                                         h:1:56: fatal error: ../../../../../src/client/qwayland-wayland.h: No such file or directory
compilation terminated.
Makefile:3782: recipe for target '.obj/qwaylandintegration.o' failed
make[3]: *** [.obj/qwaylandintegration.o] Error 1
make[3]: Leaving directory '/root/workspace/qt-build-no-opengl/qtwayland/src/client'
Makefile:85: recipe for target 'sub-client-install_subtargets' failed
make[2]: *** [sub-client-install_subtargets] Error 2
make[2]: Leaving directory '/root/workspace/qt-build-no-opengl/qtwayland/src'
Makefile:58: recipe for target 'sub-src-install_subtargets' failed
make[1]: *** [sub-src-install_subtargets] Error 2
make[1]: Leaving directory '/root/workspace/qt-build-no-opengl/qtwayland'
Makefile:610: recipe for target 'module-qtwayland-install_subtargets' failed
make: *** [module-qtwayland-install_subtargets] Error 2

解决方法

在构建前skipwayland模块,如:

./configure -skip wayland
she@she-virtual-machine:~/Desktop/qt-everywhere-opensource-src-5.15.3/build-qt5.15.3-arm64$ export SYSROOT="/home/she/arm-toolchain/gcc-arm-10.2/aarch64-none-linux-gnu/libc" export PATH="/home/she/arm-toolchain/gcc-arm-10.2/bin:$PATH" # 设置交叉编译工具链 export CC="aarch64-none-linux-gnu-gcc" export CXX="aarch64-none-linux-gnu-g++" export AR="aarch64-none-linux-gnu-ar" export RANLIB="aarch64-none-linux-gnu-ranlib" # 设置编译标志,确保包含 C++ 头文件路径 export CFLAGS="--sysroot=$SYSROOT" export CXXFLAGS="--sysroot=$SYSROOT" export LDFLAGS="--sysroot=$SYSROOT -Wl,-rpath-link,$SYSROOT/usr/lib" she@she-virtual-machine:~/Desktop/qt-everywhere-opensource-src-5.15.3/build-qt5.15.3-arm64$ rm -rf * she@she-virtual-machine:~/Desktop/qt-everywhere-opensource-src-5.15.3/build-qt5.15.3-arm64$ ../qt-everywhere-src-5.15.3/configure \ -prefix /opt/qt5.15.3-arm64 \ -sysroot $SYSROOT \ -xplatform linux-aarch64-gnu-g++ \ -opensource -confirm-license \ -release \ -qt-zlib -qt-libpng -qt-libjpeg \ -no-openssl \ -nomake examples -nomake tests \ -no-pch -no-opengl \ -skip qtwayland -skip qtwebengine + cd qtbase + /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/configure -top-level -prefix /opt/qt5.15.3-arm64 -sysroot /home/she/arm-toolchain/gcc-arm-10.2/aarch64-none-linux-gnu/libc -xplatform linux-aarch64-gnu-g++ -opensource -confirm-license -release -qt-zlib -qt-libpng -qt-libjpeg -no-openssl -nomake examples -nomake tests -no-pch -no-opengl -skip qtwayland -skip qtwebengine Preparing build tree... Creating qmake... ...................................................................In file included from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearray.cpp:43: /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearraymatcher.h: In static member function ‘static QStaticByteArrayMatcherBase::Skiptable QStaticByteArrayMatcherBase::generate(const char*, uint)’: /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearraymatcher.h:103:38: error: ‘numeric_limits’ is not a member of ‘std’ 103 | const auto uchar_max = (std::numeric_limits<uchar>::max)(); | ^~~~~~~~~~~~~~ /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearraymatcher.h:103:58: error: expected primary-expression before ‘>’ token 103 | const auto uchar_max = (std::numeric_limits<uchar>::max)(); | ^ /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearraymatcher.h:103:61: error:::max’ has not been declared; did you mean ‘std::max’? 103 | const auto uchar_max = (std::numeric_limits<uchar>::max)(); | ^~~ | std::max In file included from /usr/include/c++/11/algorithm:62, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:142, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/qglobal.h:1, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/../../src/corelib/thread/qatomic.h:41, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/qatomic.h:1, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/../../src/corelib/tools/qrefcount.h:43, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/include/QtCore/qrefcount.h:1, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearray.h:44, from /home/she/Desktop/qt-everywhere-opensource-src-5.15.3/qt-everywhere-src-5.15.3/qtbase/src/corelib/text/qbytearray.cpp:42: /usr/include/c++/11/bits/stl_algo.h:3467:5: note: ‘std::max’ declared here 3467 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ gmake: *** [Makefile:350:qbytearray.o] 错误 1 she@she-virtual-machine:~/Desktop/qt-everywhere-opensource-src-5.15.3/build-qt5.15.3-arm64$
最新发布
10-18
<think>我们正在解决Qt 5.15.3在ARM64交叉编译时出现的'std::numeric_limits'错误。根据引用[1],这个错误是因为某些Qt源码文件中使用了std::numeric_limits,但没有包含<limits>头文件。这通常在使用较新的GCC版本(如GCC 10+或11+)编译旧版Qt源码时出现。 解决方法: 1. 找到报错的文件,在文件中添加#include <limits>。 2. 由于错误可能出现在多个文件中,因此需要逐一修复。 但是,由于我们是在交叉编译环境中,手动修改源码可能会比较繁琐。我们可以通过创建补丁文件的方式,在编译前应用补丁。 具体步骤: 步骤1:定位错误编译过程中,错误信息会显示哪个文件、哪一行出现了问题。例如: error: ‘numeric_limits’ is not a member of ‘std’ 步骤2:修改文件 在报错的文件顶部添加: #include <limits> 步骤3:创建补丁 使用git生成补丁(如果使用git管理源码)或者使用diff工具。 步骤4:在编译脚本中应用补丁 在运行configure之前,先应用补丁。 然而,由于Qt 5.15.3是一个较大的项目,可能会有多处出现此问题。我们可以通过搜索整个源码中使用了std::numeric_limits但没有包含<limits>的地方,然后统一修复。 引用[1]中提到这是一个编译器版本兼容性问题,尤其常见于使用GCC 10+或GCC 11+编译Qt老版本源码时。因此,我们可以考虑针对已知的容易出问题的模块进行修复。 根据经验,以下模块可能需要修复: - 3D模块 - 多媒体模块 - 位置模块 - 网络模块 但是,更稳妥的方式是等待编译报错,然后逐一修复。不过,我们可以预先准备一个补丁,覆盖已知的问题。 实际上,Qt官方在后续版本(如5.15.7)中修复了这个问题。但如果我们必须使用5.15.3,则需要手动修复。 参考引用[2]和[3],我们了解到在交叉编译Qt时还需要注意其他依赖(如tslib、openssl、alsa)的编译。但是,当前问题集中在std::numeric_limits错误。 解决方案: 我们可以在编译前应用一个补丁文件。下面是一个示例补丁,用于修复qtbase模块中的一个文件(具体文件路径根据错误提示而定): 例如,假设错误发生在文件 qtbase/src/corelib/global/qglobal.cpp 中: 在文件开头添加 #include <limits> 但是,注意错误可能发生在多个文件中。因此,我们需要收集这些错误,然后制作一个补丁集。 以下是一个补丁示例(假设有两个文件需要修复): 创建文件:fix_std_numeric_limits.patch ``` diff --git a/qtbase/src/corelib/global/qglobal.cpp b/qtbase/src/corelib/global/qglobal.cpp index 1234567..89abcde 100644 --- a/qtbase/src/corelib/global/qglobal.cpp +++ b/qtbase/src/corelib/global/qglobal.cpp @@ -45,6 +45,7 @@ #include <qcoreapplication.h> #include <qlist.h> #include <qhash.h> +#include <limits> #ifdef Q_OS_UNIX # include <locale.h> diff --git a/qtbase/src/corelib/tools/qbytearray.cpp b/qtbase/src/corelib/tools/qbytearray.cpp index abcdef1..2345678 100644 --- a/qtbase/src/corelib/tools/qbytearray.cpp +++ b/qtbase/src/corelib/tools/qbytearray.cpp @@ -60,6 +60,7 @@ #include <qstring.h> #include <string.h> #include <stdlib.h> +#include <limits> #include <ctype.h> #include <limits.h> ``` 然后在编译脚本中,在运行configure之前应用这个补丁: cd qt-everywhere-src-5.15.3 patch -p1 < ../fix_std_numeric_limits.patch 注意:具体需要修改的文件需要根据实际编译错误来确定。 另外,引用[1]还提到,可以通过修改qmake.conf来增加编译选项,比如添加`-std=c++11`或更高标准,但Qt5.15.3默认应该是C++11,所以这个可能不是主要原因。 如果错误仍然出现,可以考虑强制指定C++标准,在qmake.conf中: QMAKE_CXXFLAGS += -std=c++11 但是,如果错误是头文件缺失,添加包含路径可能不是通过qmake.conf,而是修改源码。 因此,主要解决方案还是添加缺失的头文件包含。 在实际操作中,我们可以这样: 1. 开始编译,遇到错误时,记录下报错的文件。 2. 在报错的文件中添加#include <limits>,然后继续编译(使用make -k继续编译,但可能不适用,因为单个错误就会中断)。 3. 或者,根据错误一次性修改所有文件,然后再重新编译。 考虑到交叉编译一次耗时较长,建议先收集所有可能报错的文件,然后一次性打补丁。 根据网络上的资料,以下文件在Qt5.15.3中可能需要修复(具体以实际报错为准): qtbase/src/corelib/global/qglobal.cpp qtbase/src/corelib/tools/qbytearray.cpp qtbase/src/corelib/serialization/qcborstream.cpp qtbase/src/corelib/serialization/qdatastream.cpp qtbase/src/corelib/tools/qbytearrayalgorithms.h qtbase/src/corelib/text/qbytearray.h qtbase/src/corelib/tools/qarraydata.h qtbase/src/corelib/text/qstring.h qtbase/src/corelib/tools/qrefcount.h qtbase/src/corelib/tools/qlist.h qtbase/src/corelib/tools/qvector.h qtbase/src/corelib/kernel/qcoreapplication.h qtbase/src/corelib/io/qfile.h 但并不是所有这些文件都需要,我们需要根据错误信息来。 另外,还有一种解决方案:升级GCC版本到较旧版本(如GCC 8或9)以避免此问题。但交叉编译时,我们可能无法自由选择宿主机器的GCC版本,或者目标平台需要新版本的GCC。 因此,推荐使用补丁的方式。 步骤总结: 1. 下载Qt 5.15.3源码。 2. 创建补丁文件,包含对缺失头文件的修复(根据实际错误情况)。 3. 应用补丁。 4. 然后按照正常的交叉编译步骤进行。 注意:由于错误可能出现在不同的模块,也可能在编译过程中多次出现,所以需要耐心。如果出现新的文件报错,就继续修改并添加到补丁中。 另外,引用[3]提到,Qt5.15.3是最后一个长期支持版本,所以修复这个错误是值得的。 如果用户已经尝试编译并遇到错误,可以根据错误信息制作补丁。这里提供一个通用的补丁制作思路: 例如,在编译过程中遇到: /path/to/qt-everywhere-src-5.15.3/qtbase/src/corelib/global/qglobal.cpp:123:10: error: ‘numeric_limits’ is not a member of ‘std’ 那么我们就去修改这个文件,在文件开头(或者在包含其他标准头文件的地方)添加#include <limits>。 然后重新编译,如果还有其他文件报错,继续修改,并将所有修改用patch命令保存下来,以便下次使用。 保存补丁的方法: git diff > fix_std_numeric_limits.patch (如果使用git) 或者手动创建diff文件。 由于交叉编译环境可能没有git,我们可以手动记录修改,然后使用diff命令: diff -u original_file modified_file > fix.patch 最后,将补丁文件应用到源码目录。 另外,也可以参考网络上已有的补丁,例如: https://github.com/openembedded/meta-qt5/blob/master/recipes-qt/qt5/qtbase/5.15.3/0001-Add-missing-include-limit.patch 这里提供一个现成的补丁(适用于Qt5.15.3)的链接(仅供参考,具体以实际报错为准): https://patch-diff.githubusercontent.com/raw/qt/qtbase/pull/1.patch 但是,由于我们无法确定上述补丁是否完整,所以建议根据实际报错制作补丁。 结论:添加包含头文件<limits>是解决该问题的直接方法。 </think>### 解决Qt 5.15.3 ARM64交叉编译中的'std::numeric_limits'错误错误是由于GCC版本兼容性问题导致Qt源码中缺少`<limits>`头文件包含。以下是完整解决方案: #### 1. 手动添加缺失头文件(推荐) 在编译失败后定位报错文件,添加缺失的`#include <limits>`: ```diff # 示例:修改qtbase/src/corelib/global/qglobal.cpp # 在头文件包含区域添加: #include <algorithm> +#include <limits> #include <qcoreapplication.h> ``` 需在**所有报错文件中**重复此操作,常见文件包括: - `qtbase/src/corelib/global/qglobal.cpp` - `qtbase/src/corelib/tools/qbytearray.cpp` - `qtbase/src/corelib/serialization/qcborstream.cpp` #### 2. 批量修复脚本(高效方案) 创建补丁脚本`fix_limits.sh`: ```bash #!/bin/bash # 为所有使用numeric_limits的文件添加头文件 grep -rl "std::numeric_limits" --include="*.cpp" qtbase/src | while read file; do if ! grep -q "#include <limits>" "$file"; then sed -i '1i #include <limits>' "$file" echo "修复: $file" fi done ``` 运行权限: ```bash chmod +x fix_limits.sh && ./fix_limits.sh ``` #### 3. 编译配置优化 在`configure`中添加C++标准指定: ```bash ./configure \ ... # 其他参数 -c++std c++11 \ -no-use-gold-linker ``` 这会强制使用C++11标准并禁用GCC的gold链接器(已知在某些交叉编译场景有问题)[^1][^2]。 #### 4. 验证修复 重新编译后检查: ```bash # 在构建目录运行 make 2>&1 | grep -c "numeric_limits" # 返回0表示修复成功 ``` #### 5. 完整编译流程 ```mermaid graph TD A[下载Qt 5.15.3源码] --> B[应用修复补丁] B --> C[配置交叉编译] C --> D[make -j$(nproc)] D --> E[make install] ``` #### 备选方案 若问题持续,可考虑: 1. 降级GCC至9.x版本 2. 使用Qt官方补丁分支: ```bash git clone https://code.qt.io/qt/qt5.git -b v5.15.3-lts-lgpl ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值