direct3d-headers: IID redefinition errors #766

Closed
opened 2023-04-29 02:33:25 +00:00 by denovodavid · 2 comments
denovodavid commented 2023-04-29 02:33:25 +00:00 (Migrated from github.com)

I've been using Zig as a build tool for learning DirectX 12 and C.
I tried to use system_sdk.zig to get the latest d3d12 headers, but I'm encountering some errors.
Specifically, errors like ...include/d3d12sdklayers.h:3442:13: error: redefinition of 'IID_ID3D12Debug1'.

Looking in the headers there are multiple DEFINE_GUID(IID_ID3D12Debug1, ... statements, which seem to be causing the errors.
I don't know if there's some compiler flag that can ignore these errors, or if the headers need fixing.

If time permits, any help here would be very much appreciated 🙏

Here's my repo of a spinning triangle: gitlab.com/denovodavid/rendering/-@5e332ebd0c/
Commenting out system_sdk.include(b, exe, .{}); in build.zig should build successfully.
Here's the build log using system_sdk:
(there are more of the same errors if you increase the error limit)

❯ zig build run
zig build-exe renderer Debug native: error: error(compilation): clang failed with stderr: In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19:
In file included from C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:475:
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:350:13: error: redefinition of 'IID_ID3D10Blob'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:343:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:537:19: warning: redefinition of typedef 'ID3DInclude' is a C11 feature [-Wtypedef-redefinition]
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:534:31: note: previous definition is here
In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19:
In file included from C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:20361:
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3441:13: error: redefinition of 'IID_ID3D12Debug'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:167:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3442:13: error: redefinition of 'IID_ID3D12Debug1'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:248:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3443:13: error: redefinition of 'IID_ID3D12Debug2'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:346:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3444:13: error: redefinition of 'IID_ID3D12Debug3'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:423:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3445:13: error: redefinition of 'IID_ID3D12Debug4'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:532:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3446:13: error: redefinition of 'IID_ID3D12Debug5'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:645:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3447:13: error: redefinition of 'IID_ID3D12DebugDevice1'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:813:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3448:13: error: redefinition of 'IID_ID3D12DebugDevice'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:920:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3449:13: error: redefinition of 'IID_ID3D12DebugDevice2'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1018:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3450:13: error: redefinition of 'IID_ID3D12DebugCommandQueue'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1141:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3451:13: error: redefinition of 'IID_ID3D12DebugCommandList1'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1228:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3452:13: error: redefinition of 'IID_ID3D12DebugCommandList'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1339:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3453:13: error: redefinition of 'IID_ID3D12DebugCommandList2'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1441:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3454:13: error: redefinition of 'IID_ID3D12SharingContract'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1565:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3455:13: error: redefinition of 'IID_ID3D12InfoQueue'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:2615:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3456:13: error: redefinition of 'IID_ID3D12InfoQueue1'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3076:13: note: previous definition is here
In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19:
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:22297:13: error: redefinition of 'IID_ID3D12Object'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:3194:13: note: previous definition is here
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:22298:13: error: redefinition of 'IID_ID3D12DeviceChild'
C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:3314:13: note: previous definition is here
fatal error: too many errors emitted, stopping now [-ferror-limit=]


zig build-exe renderer Debug native: error: the following command failed with 1 compilation errors:
C:\Users\david.holland\scoop\apps\zig-dev\current\zig.exe build-exe -cflags -std=c99 -DCOBJMACROS -O0 -gdwarf -- C:\Users\david.holland\Dev\rendering\src\main.c -ldxgi -ld3d12 -ld3dcompiler_47 -lc --cache-dir C:\Users\david.holland\Dev\rendering\zig-cache --global-cache-dir C:\Users\david.holland\AppData\Local\zig --name renderer -I C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include -L C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\lib --listen=-
Build Summary: 1/6 steps succeeded; 1 failed (disable with -fno-summary)
run transitive failure
+- run renderer transitive failure
   +- zig build-exe renderer Debug native 1 errors
   +- install transitive failure
      +- install renderer transitive failure
      |  +- zig build-exe renderer Debug native (reused)
      +- install src\shader.hlsl to bin/shader.hlsl cached
C:\Users\david.holland\Dev\rendering\src\main.c:1:1: error: unable to build C object: clang exited with code 1
I've been using Zig as a build tool for learning DirectX 12 and C. I tried to use `system_sdk.zig` to get the latest d3d12 headers, but I'm encountering some errors. Specifically, errors like `...include/d3d12sdklayers.h:3442:13: error: redefinition of 'IID_ID3D12Debug1'`. Looking in the headers there are multiple `DEFINE_GUID(IID_ID3D12Debug1, ...` statements, which seem to be causing the errors. I don't know if there's some compiler flag that can ignore these errors, or if the headers need fixing. If time permits, any help here would be very much appreciated 🙏 Here's my repo of a spinning triangle: https://gitlab.com/denovodavid/rendering/-/tree/5e332ebd0c2c1e634757e067fb7982d953bef990/ Commenting out `system_sdk.include(b, exe, .{});` in `build.zig` should build successfully. Here's the build log using `system_sdk`: (there are more of the same errors if you increase the error limit) ``` ❯ zig build run zig build-exe renderer Debug native: error: error(compilation): clang failed with stderr: In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19: In file included from C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:475: C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:350:13: error: redefinition of 'IID_ID3D10Blob' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:343:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:537:19: warning: redefinition of typedef 'ID3DInclude' is a C11 feature [-Wtypedef-redefinition] C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3dcommon.h:534:31: note: previous definition is here In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19: In file included from C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:20361: C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3441:13: error: redefinition of 'IID_ID3D12Debug' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:167:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3442:13: error: redefinition of 'IID_ID3D12Debug1' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:248:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3443:13: error: redefinition of 'IID_ID3D12Debug2' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:346:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3444:13: error: redefinition of 'IID_ID3D12Debug3' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:423:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3445:13: error: redefinition of 'IID_ID3D12Debug4' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:532:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3446:13: error: redefinition of 'IID_ID3D12Debug5' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:645:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3447:13: error: redefinition of 'IID_ID3D12DebugDevice1' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:813:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3448:13: error: redefinition of 'IID_ID3D12DebugDevice' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:920:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3449:13: error: redefinition of 'IID_ID3D12DebugDevice2' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1018:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3450:13: error: redefinition of 'IID_ID3D12DebugCommandQueue' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1141:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3451:13: error: redefinition of 'IID_ID3D12DebugCommandList1' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1228:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3452:13: error: redefinition of 'IID_ID3D12DebugCommandList' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1339:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3453:13: error: redefinition of 'IID_ID3D12DebugCommandList2' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1441:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3454:13: error: redefinition of 'IID_ID3D12SharingContract' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:1565:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3455:13: error: redefinition of 'IID_ID3D12InfoQueue' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:2615:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3456:13: error: redefinition of 'IID_ID3D12InfoQueue1' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12sdklayers.h:3076:13: note: previous definition is here In file included from C:\Users\david.holland\Dev\rendering\src\main.c:19: C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:22297:13: error: redefinition of 'IID_ID3D12Object' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:3194:13: note: previous definition is here C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:22298:13: error: redefinition of 'IID_ID3D12DeviceChild' C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include/d3d12.h:3314:13: note: previous definition is here fatal error: too many errors emitted, stopping now [-ferror-limit=] zig build-exe renderer Debug native: error: the following command failed with 1 compilation errors: C:\Users\david.holland\scoop\apps\zig-dev\current\zig.exe build-exe -cflags -std=c99 -DCOBJMACROS -O0 -gdwarf -- C:\Users\david.holland\Dev\rendering\src\main.c -ldxgi -ld3d12 -ld3dcompiler_47 -lc --cache-dir C:\Users\david.holland\Dev\rendering\zig-cache --global-cache-dir C:\Users\david.holland\AppData\Local\zig --name renderer -I C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\include -L C:\Users\david.holland\AppData\Local\mach\sdk-windows-x86_64\lib --listen=- Build Summary: 1/6 steps succeeded; 1 failed (disable with -fno-summary) run transitive failure +- run renderer transitive failure +- zig build-exe renderer Debug native 1 errors +- install transitive failure +- install renderer transitive failure | +- zig build-exe renderer Debug native (reused) +- install src\shader.hlsl to bin/shader.hlsl cached C:\Users\david.holland\Dev\rendering\src\main.c:1:1: error: unable to build C object: clang exited with code 1 ```
emidoots commented 2023-05-07 21:39:38 +00:00 (Migrated from github.com)

Thanks for filing this. I just now had a chance to quickly look into it; and I agree it looks like the headers are wrong here.

If I had to guess, this issue was probably fixed upstream and we'll need to update our version of the headers in order to fix this. This is.. not exactly a trivial process: Microsoft has refused to open-source the IDL files used to generate these headers, so the open-source community (developers behind Wine, Valve/Proton, MinGW, etc.) are instead reproducing them by hand which is an arduous process - and is why Zig's DirectX headers are not totally up-to-date, too.

For Mach, in order to get updated DirectX headers in the meantime, we have the system-sdk headers as you noted: these come from a fork of Microsoft's proprietary IDL files which we modified to be somewhat translatable using WIDL (Wine's IDL -> .h compiler) so as to be compatible with clang/zig. We'll need to update that fork and recompile with WIDL in order to see if that fixes the issue.

I will get around to this, but it may be some time. A quicker workaround for your exact usecase would be to fork and directly patch the .h files.

Thanks for filing this. I just now had a chance to quickly look into it; and I agree it looks like the headers are wrong here. If I had to guess, this issue was probably fixed upstream and we'll need to update our version of the headers in order to fix this. This is.. not exactly a trivial process: Microsoft [has refused to open-source the IDL files](https://github.com/microsoft/win32metadata/issues/766) used to generate these headers, so the open-source community (developers behind Wine, Valve/Proton, MinGW, etc.) are instead reproducing them by hand which is an arduous process - and is why Zig's DirectX headers are not totally up-to-date, too. For Mach, in order to get updated DirectX headers in the meantime, we have the system-sdk headers as you noted: these come from [a fork](https://github.com/slimsag/win32metadata) of Microsoft's proprietary IDL files which we modified to be somewhat translatable using WIDL (Wine's IDL -> .h compiler) so as to be compatible with clang/zig. We'll need to update that fork and recompile with WIDL in order to see if that fixes the issue. I will get around to this, but it may be some time. A quicker workaround for your exact usecase would be to fork and directly patch the .h files.
emidoots commented 2024-12-31 02:24:50 +00:00 (Migrated from github.com)
https://github.com/hexops/mach/issues/1172
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#766
No description provided.