www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Import C under Windows 10

reply DLearner <bmqazwsx123 gmail.com> writes:
This relates to:

```
DMD64 D Compiler v2.112.0
Copyright (C) 1999-2025 by The D Language Foundation, All Rights 
Reserved written by Walter Bright

```

While trying to compile and run hello.c (ie trying out Import C):

```
#include <stdio.h>
int main()
{
    printf("Hello world.\n");
    return 0;
}

```

I got

```
Error: cl.exe not found. Please ensure that Visual Studio Build 
Tools are installed and properly configured.
```
despite repeatedly downloading everything I could find relating 
to Visual Studio 2019.

FWIW, isn't 'cl.exe' MS's _own_ C compiler - I wanted to use the 
C compiler within DMD.

Ideas?
Apr 14
next sibling parent Serg Gini <kornburn yandex.ru> writes:
On Tuesday, 14 April 2026 at 14:25:29 UTC, DLearner wrote:
 Ideas?
I don't... just wanted to say that I admire your passion of trying to make ImportC working on "hello world" example.. First try in 2023: https://forum.dlang.org/post/tq76ke$2s28$1 digitalmars.com Then in 2024: https://forum.dlang.org/thread/azwhxaopahmquhbcczku forum.dlang.org Hopefully 2026 will become the year when ImportC will start working for you! Never give up! Never surrender!
Apr 14
prev sibling next sibling parent drug007 <drug2004 bk.ru> writes:
On 4/14/26 17:25, DLearner wrote:
 This relates to:
 
 ```
 DMD64 D Compiler v2.112.0
 Copyright (C) 1999-2025 by The D Language Foundation, All Rights 
 Reserved written by Walter Bright
 
 ```
 
 While trying to compile and run hello.c (ie trying out Import C):
 
 ```
 #include <stdio.h>
 int main()
 {
     printf("Hello world.\n");
     return 0;
 }
 
 ```
 
 I got
 
 ```
 Error: cl.exe not found. Please ensure that Visual Studio Build Tools 
 are installed and properly configured.
 ```
 despite repeatedly downloading everything I could find relating to 
 Visual Studio 2019.
 
 FWIW, isn't 'cl.exe' MS's _own_ C compiler - I wanted to use the C 
 compiler within DMD.
 
 Ideas?
I don't use Windows so I can't help you but despite the fact that cl.exe is MS's own C compiler, dmd uses C compiler just to call the corresponding preprocessor. You can call it yourself and feed preprocessed files to dmd directly. You don't need any C compiler but you need a C preprocessor
Apr 14
prev sibling next sibling parent reply Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Tuesday, 14 April 2026 at 14:25:29 UTC, DLearner wrote:
 This relates to:

 ```
 DMD64 D Compiler v2.112.0
 Copyright (C) 1999-2025 by The D Language Foundation, All 
 Rights Reserved written by Walter Bright

 ```

 While trying to compile and run hello.c (ie trying out Import 
 C):

 ```
 #include <stdio.h>
 int main()
 {
    printf("Hello world.\n");
    return 0;
 }

 ```

 I got

 ```
 Error: cl.exe not found. Please ensure that Visual Studio Build 
 Tools are installed and properly configured.
 ```
 despite repeatedly downloading everything I could find relating 
 to Visual Studio 2019.

 FWIW, isn't 'cl.exe' MS's _own_ C compiler - I wanted to use 
 the C compiler within DMD.

 Ideas?
Usually, Windows Command Prompt does not automatically recognize VS compilers (due to PATH issues). Just run everything in a x64 Native Tools Command Prompt for VS 2019 (or 32 bit).
Apr 15
parent reply drug007 <drug2004 bk.ru> writes:
On 4/15/26 10:20, Ferhat Kurtulmuş wrote:
 
 Usually, Windows Command Prompt does not automatically recognize VS 
 compilers (due to PATH issues). Just run everything in a x64 Native 
 Tools Command Prompt for VS 2019 (or 32 bit).
Exactly! This link can be useful - https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=visualstudio
Apr 15
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Wednesday, 15 April 2026 at 10:49:14 UTC, drug007 wrote:
 On 4/15/26 10:20, Ferhat Kurtulmuş wrote:
 
 Usually, Windows Command Prompt does not automatically 
 recognize VS compilers (due to PATH issues). Just run 
 everything in a x64 Native Tools Command Prompt for VS 2019 
 (or 32 bit).
Exactly! This link can be useful - https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=visualstudio
Thanks! For the record, by clearing out all earlier Visual Studio's and downloading Visual Studio 2026, and using 'Developer Powershell', I _finally_ made it work. However, would it not be better if the Windows DMD download was 'battery included', in the sense that the built-in C compiler did it's own preprocessing?
Apr 15
parent reply drug007 <drug2004 bk.ru> writes:
On 4/15/26 21:54, DLearner wrote:
 On Wednesday, 15 April 2026 at 10:49:14 UTC, drug007 wrote:
 On 4/15/26 10:20, Ferhat Kurtulmuş wrote:
 Usually, Windows Command Prompt does not automatically recognize VS 
 compilers (due to PATH issues). Just run everything in a x64 Native 
 Tools Command Prompt for VS 2019 (or 32 bit).
Exactly! This link can be useful - https://learn.microsoft.com/en-us/ visualstudio/ide/reference/command-prompt-powershell?view=visualstudio
Thanks! For the record, by clearing out all earlier Visual Studio's and downloading Visual Studio 2026, and using 'Developer Powershell', I _finally_ made it work. However, would it not be better if the Windows DMD download was 'battery included', in the sense that the built-in C compiler did it's own preprocessing?
I don't think it's worth it. Too much efforts for nothing. dmd does not contain an internal C compiler, not at all, dmd translates C to D AST. And dmd does not contain a preprocessor in any form. So you need to write C preprocessor from scratch.
Apr 15
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Wednesday, 15 April 2026 at 19:28:33 UTC, drug007 wrote:
 On 4/15/26 21:54, DLearner wrote:
[...]
 
 However, would it not be better if the Windows DMD download 
 was 'battery included', in the sense that the built-in C 
 compiler did it's own preprocessing?
I don't think it's worth it. Too much efforts for nothing. dmd does not contain an internal C compiler, not at all, dmd translates C to D AST. And dmd does not contain a preprocessor in any form. So you need to write C preprocessor from scratch.
If the maintainers of DMD don't wish to write a new preprocessor, could not one of the four or five preprocessors mentioned in 42.4.2 be somehow incorporated? It's just that cl.exe is less than 1Mb, yet the Visual Studio download to be able to use it is over 10Gb! And one seems to be forced to use the 'Developer Powershell', which is very sluggish compared to the normal terminal window (if you run DMD in the normal terminal window it can't find cl.exe).
Apr 16
next sibling parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 16 April 2026 at 19:30:48 UTC, DLearner wrote:
 It's just that cl.exe is less than 1Mb, yet the Visual Studio 
 download to be able to use it is over 10Gb!
Unfortunately, Microsoft doesn't allow redistributing Visual Studio Build Tools.
 And one seems to be forced to use the 'Developer Powershell', 
 which is very sluggish compared to the normal terminal window 
 (if you run DMD in the normal terminal window it can't find 
 cl.exe).
DMD has a bunch of logic trying to find the Visual Studio installation path: https://github.com/dlang/dmd/blob/2a47bdaafa58a90af9d6ce621f561ef9eb0bc5fd/compiler/src/dmd/vsoptions.d#L213 Did you install it in a special way, or modify your registry / environment variables in any way?
Apr 16
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Thursday, 16 April 2026 at 19:46:48 UTC, Dennis wrote:
 On Thursday, 16 April 2026 at 19:30:48 UTC, DLearner wrote:
[...]
 DMD has a bunch of logic trying to find the Visual Studio 
 installation path:

 https://github.com/dlang/dmd/blob/2a47bdaafa58a90af9d6ce621f561ef9eb0bc5fd/compiler/src/dmd/vsoptions.d#L213

 Did you install it in a special way, or modify your registry / 
 environment variables in any way?
Installed using Windows installer from the Dlang website. Registry not modified. Over time, some of the user (not system) paths were added to. The system paths are unmodified in any way (by me). FWIW: I noticed that there FOUR different locations for cl.exe - I thought this bizarre. Has anyone tested inputC using VS2026 - maybe MS changed paths?
Apr 16
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Thursday, 16 April 2026 at 21:49:40 UTC, DLearner wrote:
 On Thursday, 16 April 2026 at 19:46:48 UTC, Dennis wrote:
 On Thursday, 16 April 2026 at 19:30:48 UTC, DLearner wrote:
[...]
Success! Leaving VS2026 alone, I un- and re-installed DMD. I can confirm that I am able to compile and run C programs from the normal Windows command prompt (as well as the sluggish 'Developer Powershell'). I do feel that consideration should be given to somehow arranging that, for a Windows installation, a mechanism should be provided such that DMD's ImportC option works _without_ having to download VS (perhaps by incorporating an existing open source preprocessor). The gross bloat and complexity of VS is not DMD's fault, but it should not be encouraged.
Apr 17
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/04/2026 9:29 PM, DLearner wrote:
 I do feel that consideration should be given to somehow arranging that, 
 for a Windows installation, a mechanism should be provided such that 
 DMD's ImportC option works /without/ having to download VS (perhaps by 
 incorporating an existing open source preprocessor). The gross bloat and 
 complexity of VS is not DMD's fault, but it should not be encouraged.
A long time ago I managed to hack clang via mingw to work as the preprocessor for dmd on Windows. No work has progressed on this front since I last tried it ages ago. But ultimately system toolchains are special things for native development. You're stuck with the official one and for Windows you get it via VS, regardless of how much you or I dislike it.
Apr 17
prev sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 17/04/2026 7:30 AM, DLearner wrote:
 If the maintainers of DMD don't wish to write a new preprocessor, could 
 not one of the four or five preprocessors mentioned in 42.4.2 be somehow 
 incorporated?
The issue isn't the preprocessor itself. Its all the variables it sets, and the headers (can just throw mingw at it).
Apr 16
prev sibling parent Michael Reed <michaelreed3540 gmail.com> writes:
On Tuesday, 14 April 2026 at 14:25:29 UTC, DLearner wrote:
 This relates to:

 ```
 DMD64 D Compiler v2.112.0
 Copyright (C) 1999-2025 by The D Language Foundation, All 
 Rights Reserved written by Walter Bright

 ```

 While trying to compile and run hello.c (ie trying out Import 
 C):

 ```
 #include <stdio.h>
 int main()
 {
    printf("Hello world.\n");
    return 0;
 }

 ```

 I got

 ```
 Error: cl.exe not found. Please ensure that Visual Studio Build 
 Tools are installed and properly configured.
 ```
 despite repeatedly downloading everything I could find relating 
 to Visual Studio 2019.

 FWIW, isn't 'cl.exe' MS's _own_ C compiler - I wanted to use 
 the C compiler within DMD.

 Ideas?
This is a pretty common frustration for anyone starting with D on Windows and it took me a while to sort out too. The root issue is that DMD on Windows relies on Microsoft's linker and build tools but doesn't always set up the PATH correctly during installation. So even if everything is downloaded, your terminal simply can't find cl.exe because it doesn't know where to look. Here's what actually works: Step 1: Don't use regular Command Prompt or PowerShell. After installing Visual Studio Build Tools, always open "x64 Native Tools Command Prompt for VS" — you'll find it in your Start menu after installation. This terminal has all the correct PATH variables pre-loaded. This alone fixes the issue for most people. Step 2: If you want to use regular terminal, you need to manually add the MSVC compiler path to your system PATH. It usually lives somewhere like: C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\[version]\bin\Hostx64\x64 Add this to your Environment Variables and cl.exe will be found from any terminal. Step 3: Verify your DMD installation. Run dmd --version first. If that works but compilation still fails, the build tools aren't linked properly. Reinstall DMD and during installation make sure it detects your Visual Studio Build Tools automatically. Step 4: Lightweight alternative. As DLearner mentioned, the full Windows SDK is 300MB+ which feels heavy just to compile a hello world. A cleaner option is using LDC (LLVM-based D compiler) which handles Windows compilation more independently without needing the full MSVC toolchain. Honestly the whole thing reminded me of something I read while researching a home project even something like finding the best window installation Baltimore contractors taught me that proper installation setup from the start saves enormous headache later. Whether it's physical windows or Windows OS toolchains — if the foundation isn't set up right, everything built on top of it causes problems. Same principle applies here. Get the build environment right first, then everything else just works. Once your environment is properly configured, that simple Hello World will compile in seconds. Don't let the setup friction discourage you D is genuinely worth learning.
May 21