From b447a5305eac8a957a506496e126c126a8461e7d Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Wed, 9 Jul 2025 00:11:05 -0300 Subject: [PATCH] Fix more build errors in mingw This PR incorporates fixes for issues reported in #71 --- src/D3D12MemAlloc.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index 6e93839..78af95f 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp @@ -34,10 +34,25 @@ #endif // Includes needed for MinGW - see #71. -#ifndef _MSC_VER - #include - // guiddef.h must be included first. - #include +// On older mingw versions, using the Agility SDK will cause linker errors unless dxguids.h is included. +// But on newer mingw versions, the includes aren't necessary thus no need to grab DirectX-Headers. +// Release cycles are slow for LTS distros on Linux, so this codeblock will need to stay for a few years. +#if defined( __MINGW64_VERSION_MAJOR ) && defined( __MINGW64_VERSION_MINOR ) && \ + defined( __MINGW64_VERSION_BUGFIX ) && defined( __ID3D12Device8_INTERFACE_DEFINED__ ) +# define D12MA_MAKE_MINGW_VERSION( x, y, z ) ( ( x << 20u ) | ( y << 10u ) | ( z ) ) +# if D12MA_MAKE_MINGW_VERSION( __MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR, \ + __MINGW64_VERSION_BUGFIX ) <= D12MA_MAKE_MINGW_VERSION( 11, 0, 1 ) +# if defined( __has_include ) +# if !__has_include( ) +# error \ + "mingw or gcc detected. dxguids.h is needed. You can grab it from https://github.com/microsoft/DirectX-Headers or if you're on Ubuntu just run sudo apt install directx-headers-dev" +# endif +# endif +# include + +# include +# endif +# undef D12MA_MAKE_MINGW_VERSION #endif ////////////////////////////////////////////////////////////////////////////////