【问题标题】:How can I build Qt 5.13.2 with GCC 11.1 on Windows?如何在 Windows 上使用 GCC 11.1 构建 Qt 5.13.2?
【发布时间】:2021-09-05 22:12:41
【问题描述】:

长期以来,我一直在使用 GCC/MinGW-w64 在 Windows 上成功构建 Qt 5。当我尝试使用 GCC 11.1 时,构建失败并出现奇怪的错误消息。我该怎么做才能让它发挥作用?

我自己使用https://github.com/niXman/mingw-buildsdevelop 分支通过以下命令构建了编译器:

../build --mode=gcc-11.1.0 --arch=x86_64 --buildroot=/c/mingw-builds/BuildRoot --update-sources --exceptions=seh --threads=posix --enable-languages=c++ --jobs=48 --rt-version=v7

然后我在 MSYS2 控制台上像这样检索 Qt:

# Ensure that the right Perl is being used to prevent the possible later compilation error "fatal error: QVector: No such file or directory"
export PATH=/c/Strawberry/perl/bin/:$PATH

cd /c
cd Libraries/
mkdir Qt
cd Qt
git clone git://code.qt.io/qt/qt5.git
cd qt5
git checkout v5.13.2
perl init-repository --module-subset=essential --berlin
cd ..

然后我尝试构建 Qt:

mkdir Build
cd Build
../qt5/configure -prefix ../Install -release -recheck-all -confirm-license -opensource -platform win32-g++ -opengl desktop -nomake examples -nomake tests -skip qtconnectivity -skip qtdeclarative -skip qtlocation -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtsensors -skip qtwebsockets -skip qtwinextras -skip qtwebchannel -skip qtwebengine
mingw32-make -j 48

但是configure 显示很多类似这样的错误:

qt5/qtbase/src/corelib/global/qendian.h:333:35: error: 'numeric_limits' is not a member of 'std'

我该如何解决?

此外,我想将它与“Open CASCADE”分发的“FreeType”库(为 MinGW 构建的版本)链接起来(参见https://dev.opencascade.org/resources/download/3rd-party-components)。这怎么可能?

【问题讨论】:

    标签: c++ qt gcc build qt5


    【解决方案1】:

    有几个问题需要解决。

    首先我必须修补 Qt,因为在 GCC 11 中,一些头文件依赖项发生了变化,并且 Qt 5.13.2 并不总是包含正确的头文件(请参阅 https://gcc.gnu.org/gcc-11/porting_to.htmlHow Can I Include Header Files by Compilation Flags?)。

    所以我加了一行

    #include <limits>
    

    #ifdef __cplusplus 块内 到文件

    qt5/qtbase/src/corelib/global/qglobal.h
    

    如果没有使用自己的 FreeType 库,则现在构建成功。

    但是当我添加configure 命令选项时

    -system-freetype -I /c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/include -L/c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/bin -L/c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/lib
    

    然后运行mingw32-make -j 48,我收到以下错误消息:

    internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:186: MapViewOfFileEx:  Attempt to access invalid address.
    

    这可以通过在configure 命令中添加选项-no-pch 来解决。调用现在看起来像这样:

    ../qt5/configure -prefix ../Install -release -recheck-all -confirm-license -no-pch -opensource -platform win32-g++ -opengl desktop -nomake examples -nomake tests -system-freetype -I /c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/include -L/c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/bin -L/c/Libraries/OpenCascade/3rdPartyMingw64/freetype-2.6.3-mingw-64/lib -skip qtconnectivity -skip qtdeclarative -skip qtlocation -skip qtmultimedia -skip qtquickcontrols -skip qtquickcontrols2 -skip qtsensors -skip qtwebsockets -skip qtwinextras -skip qtwebchannel -skip qtwebengine
    

    运行configure 后,构建可以运行

    mingw32-make -j 48
    

    它成功了。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    相关资源
    最近更新 更多