build failure - '_uuidof' was not declared in this scope
-
I'm trying to build Qt using MINGW64. I'm using the following commands:
set PATH=D:\Utility\perl\perl\bin;D:\msys64\mingw64\bin;D:\msys64\usr\bin;D:\Windows Kits\10\bin\10.0.19041.0\x64;%PATH% ..\configure -developer-build -opensource -nomake examples -nomake tests -opengl desktop -confirm-license mingw32-make -j16
But it is failing with the following error:
D:/Projects/lib/qt5/qtdeclarative/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp:224:83: error: expected primary-expression before ')' token 224 | HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr); | ^ D:/Projects/lib/qt5/qtdeclarative/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp:224:63: error: '_uuidof' was not declared in this scope 224 | HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr); | ^~~~~~~
-
@gyorokpeter said in build failure - '_uuidof' was not declared in this scope:
I'm trying to build Qt using MINGW64
I am not an expert, but
_uuidof()
is an MSVC extension. It is not avilable in MINGW, e.g. see https://stackoverflow.com/questions/18606546/how-to-use-uuidof-in-mingw. So, not that I know why, unless somewhere in MINGW-Qt there is supposed to be a#define _uuidof()
to something known to MINGW, it sounds to me like your compilation is for MSVC? -
Shouldn't the configure script take care of this accordingly?
If I change_uuidof
to__uuidof
(with two underscores) it gets past that point, but then it complains aboutD3D12Debug
not being defined. I looked it up in the Windows SDK and it's found ind3d12sdklayers.h
. So if I add an include of this file toqsgd3d12engine.cpp
that works to. Now I'm stuck because I get a linker error thatMAX_SWAP_CHAIN_BUFFER_COUNT
is not defined. This is despite the header file in which that is defined (qsgd3d12engine_p_p.h
) being included in the .cpp file. -
@gyorokpeter
Bear in mind I know nothing about this! You seem to have issues compiling Windows D3D (DirectX12) code with MinGW. I don't know whether that's even supposed to work, or whether it really wants MSVC compiler. Google for, say,d3d12 mingw
, and you get some hits concerning MinGW issues, e.g. https://stackoverflow.com/questions/64789975/finding-directx12-libraries-with-cmake-and-mingw. -
It might be the case that full build of Qt is rarely tested with MINGW64. For example:
class QSGD3D12EnginePrivate ... static const int MAX_SWAP_CHAIN_BUFFER_COUNT = 4; static const int MAX_FRAME_IN_FLIGHT_COUNT = 4;
These appear in a .h file (
declarative\src\plugins\scenegraph\d3d12\qsgd3d12engine_p_p.h
), but I get a linker error if these don't also appear in a .cpp file. Alternatively changing both toinline
also works.So what I'm doing right now is making small hacks just to make the build pass, but it would be good to have them properly solved in the upstream code.
-
@gyorokpeter said in build failure - '_uuidof' was not declared in this scope:
but it would be good to have them properly solved in the upstream code.
I'm pretty confident that Qt compiles fine with MinGW 64 - see for example https://testresults.qt.io/coin/integration/qt/qtbase/tasks/1626435963 (search for Windows10-Mingw8-x64-host) and you just pick up an ancient compiler because of your MSYS paths. MSYS is not needed for Qt to be build on Windows with MinGW.
-
@Christian-Ehrlicher Your link no longer works - but given as it has Mingw8 in the name, I'm assuming that you were referring to a Qt 5 build with MinGW 8.
While officially Qt 5 is dead now and no longer actively supported for open-source, I also ran into the issue @gyorokpeter was having. Specifically, I am using MinGW 11.2 (the bundled MinGW compiler for Qt 6) to compile the latest Qt 5 LTS.
So to conclude, yes, Qt compiles fine with MinGW, but Qt 5 breaks when using a newer MinGW compiler. It passes the d3d12 config.test in qt/qtdeclarative, but then fails to compile the rest of the d3d12 plugin.
This is what I had to do to make Qt 5 compile again under MinGW 11.2:
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp index 75bde2c66b..3594878eca 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12engine.cpp @@ -221,7 +221,7 @@ static void getHardwareAdapter(IDXGIFactory1 *factory, IDXGIAdapter1 **outAdapte if (SUCCEEDED(factory->EnumAdapters1(adapterIndex, &adapter))) { adapter->GetDesc1(&desc); const QString name = QString::fromUtf16((char16_t *) desc.Description); - HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr); + HRESULT hr = D3D12CreateDevice(adapter.Get(), fl, __uuidof(ID3D12Device), nullptr); if (SUCCEEDED(hr)) { qCDebug(QSG_LOG_INFO_GENERAL, "Using requested adapter '%s'", qPrintable(name)); *outAdapter = adapter.Detach(); @@ -238,7 +238,7 @@ static void getHardwareAdapter(IDXGIFactory1 *factory, IDXGIAdapter1 **outAdapte if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) continue; - if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), fl, _uuidof(ID3D12Device), nullptr))) { + if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), fl, __uuidof(ID3D12Device), nullptr))) { const QString name = QString::fromUtf16((char16_t *) desc.Description); qCDebug(QSG_LOG_INFO_GENERAL, "Using adapter '%s'", qPrintable(name)); break; diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12engine_p_p.h b/src/plugins/scenegraph/d3d12/qsgd3d12engine_p_p.h index a95cbb1cbb..54a2c4dc8f 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12engine_p_p.h +++ b/src/plugins/scenegraph/d3d12/qsgd3d12engine_p_p.h @@ -55,6 +55,7 @@ #include <QCache> #include <d3d12.h> +#include <d3d12sdklayers.h> #include <dxgi1_4.h> #include <dcomp.h> #include <wrl/client.h> @@ -263,8 +264,8 @@ private: void beginFrameDraw(); void endDrawCalls(bool lastInFrame = false); - static const int MAX_SWAP_CHAIN_BUFFER_COUNT = 4; - static const int MAX_FRAME_IN_FLIGHT_COUNT = 4; + static inline const int MAX_SWAP_CHAIN_BUFFER_COUNT = 4; + static inline const int MAX_FRAME_IN_FLIGHT_COUNT = 4; bool initialized = false; bool inFrame = false;