You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MinGW静态编译Qt 6.4.0时遇到编译错误求助

问题描述

使用MinGW静态编译Qt 6.4.0时,已通过将Windows Kits 10中的fxc.exe添加到系统路径解决了找不到fxc的问题,但现在出现新的编译错误。

配置命令:

configure.bat -release -static -static-runtime -no-pch -optimize-size -opengl desktop -platform win32-g++ -prefix "C:\qt\6.4.0static\qt-static" -skip webengine -nomake tools -nomake tests -nomake examples

操作系统:Windows 11 Pro (21H2)

编译报错详情
qsgd3d12engine.cpp: In member function 'D3D12_CPU_DESCRIPTOR_HANDLE QSGD3D12CPUDescriptorHeapManager::allocate(D3D12_DESCRIPTOR_HEAP_TYPE)':
qsgd3d12engine.cpp:121:41: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
  121 |             for (int bucket = 0; bucket < _countof(heap.freeMap); ++bucket)
      |                                         ^
qsgd3d12engine.cpp:157:23: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
  157 |     for (int i = 1; i < _countof(heap.freeMap); ++i)
      |                       ^
qsgd3d12engine.cpp: In function 'void getHardwareAdapter(IDXGIFactory1*, IDXGIAdapter1**)':
qsgd3d12engine.cpp:224:83: error: expected primary-expression before ')' token
  224 |             HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr);
      |                                                                                   ^
qsgd3d12engine.cpp:224:63: error: '_uuidof' was not declared in this scope
  224 |             HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr);
      |                                                               ^~~~~~~
In file included from C:/msys64/mingw64/include/winbase.h:2811,
                 from C:/msys64/mingw64/include/windows.h:70,
                 from C:/Qt/dev/Qt/src/qtbase/src/corelib/global/qt_windows.h:64,
                 from C:\Qt\dev\Qt\src\qtbase\include/QtCore/qt_windows.h:1,
                 from C:/Qt/dev/Qt/src/qtbase/src/gui/opengl/qopengl.h:49,
                 from C:\Qt\dev\Qt\src\qtbase\include/QtGui/qopengl.h:1,
                 from C:/Qt/dev/Qt/src/qtdeclarative/src/quick/scenegraph/coreapi/qsggeometry.h:44,
                 from ..\..\..\..\include\QtQuick/qsggeometry.h:1,
                 from qsgd3d12engine_p.h:57,
                 from qsgd3d12engine.cpp:40:
qsgd3d12engine.cpp:241:80: error: expected primary-expression before ')' token
  241 |         if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr))) {
      |                                                                                ^
qsgd3d12engine.cpp:241:60: error: '_uuidof' was not declared in this scope
  241 |         if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr))) {
      |                                                            ^~~~~~~
解决方法

方案一:禁用D3D12模块(简单直接)

当前配置指定了-opengl desktop,可以直接在configure命令中添加-no-d3d12参数,跳过D3D12相关代码的编译,从根源上避免这个问题。修改后的配置命令如下:

configure.bat -release -static -static-runtime -no-pch -optimize-size -opengl desktop -platform win32-g++ -prefix "C:\qt\6.4.0static\qt-static" -skip webengine -nomake tools -nomake tests -nomake examples -no-d3d12

方案二:修改代码适配MinGW

如果需要保留D3D12支持,可修改报错代码适配MinGW:

  1. 打开qsgd3d12engine.cpp文件,找到第224行和241行的_uuidof(ID3D12Device),替换为IID_ID3D12Device(MinGW通过该方式获取接口UUID)。
  2. 对于符号比较警告,将循环变量类型从int改为size_t(比如int bucket改为size_t bucket),消除有符号与无符号整数的比较冲突。

内容的提问来源于stack exchange,提问作者ljn7

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 01:55:18