Thread overview
August 12

Hello.

I wanted to use the latest version of stb library https://code.dlang.org/packages/stb . Apparently it switched from manual D bindings to using ImportC feature instead. The package is importing https://github.com/Temtaime/stb/blob/main/source/stb_main.c which in turns is #include'ing several C header files such as https://github.com/Temtaime/stb/blob/main/lib/stb_image.h

Now this header files imports several C stdlib headers like:

#include <stdarg.h>
#include <stddef.h> // ptrdiff_t on osx
#include <stdlib.h>
#include <string.h>
#include <limits.h>

When I try to compile such code it fails because it can't find the C stdlib:

C:\Users\haxx\AppData\Local\dub\packages\stb-2.0.3\stb\source../lib/stb.h(200): fatal error C1034: stdarg.h: no include path set
C:\Users\haxx\AppData\Local\dub\packages\stb-2.0.3\stb\source\stb\package.d(2,15): Error: C preprocess command C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe failed for file C:\Users\haxx\AppData\Local\dub\packages\stb-2.0.3\stb\source\stb_main.c, exit status 2

What can I do to fix this issue? I'm running DMD v2.102 on Windows 11.

August 13
On Windows you need to use the native tool command prompt shortcut that comes with Visual Studio (in start menu) for ImportC to work.

Without that, the environment variables won't be setup correctly.

For repeated builds locally you can copy the appropriate variables out and apply them to say your IDE.
August 12
On Saturday, 12 August 2023 at 18:52:27 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On Windows you need to use the native tool command prompt shortcut that comes with Visual Studio (in start menu) for ImportC to work.
>
> Without that, the environment variables won't be setup correctly.
>
> For repeated builds locally you can copy the appropriate variables out and apply them to say your IDE.

If OP is using dub, shouldn't dub do that automaticaly?

From a UX point of view, this seems like a downgrade, ImportC is great and it shouldn't cause frictions, i might look into trying to send a PR to dub
August 13
I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub.
August 13
On Sunday, 13 August 2023 at 06:43:10 UTC, Richard (Rikki) Andrew Cattermole wrote:
> I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub.

Oh better, let's try to send a PR to dmd then for today, it shouldn't be hard if you say it already know where VS is
August 14
On 14/08/2023 3:23 AM, ryuukk_ wrote:
> On Sunday, 13 August 2023 at 06:43:10 UTC, Richard (Rikki) Andrew Cattermole wrote:
>> I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub.
> 
> Oh better, let's try to send a PR to dmd then for today, it shouldn't be hard if you say it already know where VS is

Knowing where VS is, is the easy part (although it is logic that has been fine tuned over a 10 year period, so not something you'd want to duplicate).

Getting the environment variables that are set up by a cobweb of batch scripts is the hard part.

We are not the first to need to do this either! https://stackoverflow.com/questions/21222223/get-environment-variables-of-child-process-in-vc
August 13
On Sunday, 13 August 2023 at 15:39:19 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 14/08/2023 3:23 AM, ryuukk_ wrote:
>> On Sunday, 13 August 2023 at 06:43:10 UTC, Richard (Rikki) Andrew Cattermole wrote:
>>> I would argue that this should be done by dmd as it knows where the VS installation is and it'll catch people out who aren't using dub.
>> 
>> Oh better, let's try to send a PR to dmd then for today, it shouldn't be hard if you say it already know where VS is
>
> Knowing where VS is, is the easy part (although it is logic that has been fine tuned over a 10 year period, so not something you'd want to duplicate).
>
> Getting the environment variables that are set up by a cobweb of batch scripts is the hard part.
>
> We are not the first to need to do this either! https://stackoverflow.com/questions/21222223/get-environment-variables-of-child-process-in-vc

Well, it's just one batch file to call, if vs path is known, then it's already all solved, i'll try to come up with a PR