www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ImportC issue?

reply DLearner <bmqazwsx123 gmail.com> writes:
C source ex01.c:
```
#include <stdio.h>
int main()
{
    printf("hello world\n");
    return 0;
}
```
'dmc ex01.c' produces message:
```
link ex01,,,user32+kernel32/noi;
```

but does generate .obj, .map and .exe files,
and the exe executes properly.

However, trying to use ImportC via 'dmd ex01.c' produces messages:
```
failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c 
/FIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h 
/Fiex01.i
Error: C preprocess command cl.exe failed for file ex01.c, exit 
status 1
```

This behaviour was repeated after a complete fresh 
re-installation of dmd & dmc from the website.
Apr 19 2023
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Yeah cl is the MSVC compiler being used for preprocessing.

So for whatever reason its not using dmc, hence the error.
Apr 19 2023
prev sibling parent reply bachmeier <no spam.net> writes:
On Wednesday, 19 April 2023 at 10:21:22 UTC, DLearner wrote:
 C source ex01.c:
 ```
 #include <stdio.h>
 int main()
 {
    printf("hello world\n");
    return 0;
 }
 ```
 'dmc ex01.c' produces message:
 ```
 link ex01,,,user32+kernel32/noi;
 ```

 but does generate .obj, .map and .exe files,
 and the exe executes properly.

 However, trying to use ImportC via 'dmd ex01.c' produces 
 messages:
 ```
 failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c 
 /FIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h 
 /Fiex01.i
 Error: C preprocess command cl.exe failed for file ex01.c, exit 
 status 1
 ```

 This behaviour was repeated after a complete fresh 
 re-installation of dmd & dmc from the website.
Did you use the switch `-m32omf`? https://dlang.org/spec/importc.html#auto-cpp
Apr 19 2023
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Wednesday, 19 April 2023 at 11:50:28 UTC, bachmeier wrote:
[...]
 Did you use the switch `-m32omf`?

 https://dlang.org/spec/importc.html#auto-cpp
No so following the references I tried every preprocessor option I could find: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c -m32omf failed launching sppn.exe ex01.c -HIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h -ED -oex01.i Error: C preprocess command sppn.exe failed for file ex01.c, exit status 1 C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c -c -m32omf failed launching sppn.exe ex01.c -HIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h -ED -oex01.i Error: C preprocess command sppn.exe failed for file ex01.c, exit status 1 C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c -c -m32mscoff failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c -c -m64 failed launching cl.exe /P /Zc:preprocessor /PD /nologo ex01.c /FIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h /Fiex01.i Error: C preprocess command cl.exe failed for file ex01.c, exit status 1 ``` Unfortunately all options failed.
Apr 19 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 20/04/2023 12:07 AM, DLearner wrote:
 Error: C preprocess command sppn.exe failed for file ex01.c, exit status 1
Did you verify that sppn is accessible in that shell? As in run it, can it be found? If not its just a PATH variable issue.
Apr 19 2023
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Wednesday, 19 April 2023 at 12:09:44 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 20/04/2023 12:07 AM, DLearner wrote:
 Error: C preprocess command sppn.exe failed for file ex01.c, 
 exit status 1
Did you verify that sppn is accessible in that shell? As in run it, can it be found? If not its just a PATH variable issue.
SPPN.exe not visible from that command prompt, but neither (using File Explorer) anywhere on the C: drive (lots of SPPNP.DLL's, in various Windows locations). If SPPN.exe essential to a component of DMD, was it not downloaded with it (and PATH modified to point to it), by the installer?
Apr 19 2023
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 20/04/2023 1:11 AM, DLearner wrote:
 If SPPN.exe essential to a component of DMD, was it not downloaded with 
 it (and PATH modified to point to it), by the installer?
It is not an essential component of dmd. It is one option in the usage of an experimental feature inside of dmd that is not ready for general use.
Apr 19 2023
prev sibling parent reply bachmeier <no spam.net> writes:
On Wednesday, 19 April 2023 at 13:11:45 UTC, DLearner wrote:
 On Wednesday, 19 April 2023 at 12:09:44 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 On 20/04/2023 12:07 AM, DLearner wrote:
 Error: C preprocess command sppn.exe failed for file ex01.c, 
 exit status 1
Did you verify that sppn is accessible in that shell? As in run it, can it be found? If not its just a PATH variable issue.
SPPN.exe not visible from that command prompt, but neither (using File Explorer) anywhere on the C: drive (lots of SPPNP.DLL's, in various Windows locations). If SPPN.exe essential to a component of DMD, was it not downloaded with it (and PATH modified to point to it), by the installer?
My understanding (from my occasional use of Windows) is that DMD installs the Community Edition of Visual Studio. That should solve your original issue, and you shouldn't need to mess with sppn.exe.
Apr 19 2023
parent DLearner <bmqazwsx123 gmail.com> writes:
On Wednesday, 19 April 2023 at 14:42:44 UTC, bachmeier wrote:
[...]
 My understanding (from my occasional use of Windows) is that 
 DMD installs the Community Edition of Visual Studio. That 
 should solve your original issue, and you shouldn't need to 
 mess with sppn.exe.
Well it took a little while, but I can confirm that if you have a D function like: ``` extern(C) void DCallee() { import core.stdc.stdio : printf; printf("Entered DCallee.\n"); printf("Exiting DCallee.\n"); } ``` called from a C function like: ``` // C Master calling D (under -betterC restrictions). #include <stdio.h> extern void DCallee(); int main() { printf("MastC Entered.\n"); DCallee(); printf("MastC Exiting.\n"); return 0; } ``` Where the compilation is run from the batch file: ``` Rem Compile, link and run batch file. IF EXIST .\DCallee.exe del .\DCallee.exe IF EXIST .\DCallee.map del .\DCallee.map IF EXIST .\DCallee.obj del .\DCallee.obj IF EXIST .\MastC.exe del .\MastC.exe IF EXIST .\MastC.map del .\MastC.map IF EXIST .\MastC.obj del .\MastC.obj dmd -m32omf -betterC -c DCallee.d dmc MastC.c DCallee.obj MastC.exe Rem Exited compile, link and run batch file. ``` Then everything runs properly. As an aside, it was a surprise to me to discover that the order of the file names in the dmc line was significant, bearing in mind MastC.c contains a 'main' function, and DCallee.d does not. As a further aside, I do recall the installer loading Visual Studio, but it didn't seem to help.
Apr 19 2023