Including windows.h

Harry Gillanders contact at harrygillanders.com
Thu Jun 25 08:33:26 UTC 2026


On Monday, 22 June 2026 at 01:33:37 UTC, Valentino Giudice wrote:
> [...]
> I know this isn't the first thread about this issue, but they
> are from years ago, so I'm writing to see if something has
> changed.
>
> Attempting to compile, through importC, on Windows, code that
> includes windows.h leads to several linker C5106 warnings and
> LNK2019 errors from link.exe.
> [...]

The reason why the linker errors occur is that ImportC doesn't 
recognise MSVC's compiler intrinsics, and so attempts to call 
them as externally defined functions.
(As they are intrinsic, they have no external definition.)

A couple of years ago I wrote up D implementations for all but 
three of MSVC's intrinsics, with optimised code for LDC, GDC, and 
DMD. Unit-tested and all. Fuzzed, even, for the floating-point 
stuff!

I submitted a PR (https://github.com/dlang/dmd/pull/16372), but 
was unable to find a way to make the compiler able to use the D 
implementations' module without the end-user having to find the 
location of the `__builtins_msvc.d` file distributed with their 
compiler so that they could then supply its path when invoking 
the compiler (which was Walter's proposed solution to the 
problem).

A second problem was that—due to the way that MSVC's intrinsics 
are declared in Windows' headers—the compiler is unable to inline 
D implementations of the intrinsics.
Again I submitted a PR with a potential solution for that, but it 
was ignored by even dlang-bot: 
https://github.com/dlang/dmd/pull/16464

To answer your question, "are there any plans to resolve this?", 
the answer is ostensibly: no.

Alas, here lies testament to my folly of trying to make ImportC 
better for targeting Windows: 
https://github.com/users/just-harry/projects/1/



More information about the Digitalmars-d mailing list