How to Use D's ImportC Compiler in a Program
Steven Schveighoffer
schveiguy at gmail.com
Wed Oct 8 02:00:59 UTC 2025
On Wednesday, 8 October 2025 at 01:38:03 UTC, David T. Oxygen
wrote:
> On Tuesday, 7 October 2025 at 17:00:51 UTC, Dejan Lekic wrote:
>> On Monday, 6 October 2025 at 15:20:06 UTC, David T. Oxygen
>> wrote:
>>> I once found that D has a ImportC compiler. It can compile C
>>> code.
>>> How to use it?
>>> I tried `dmd hello.c` but it didn't work. Instead,it did
>>> nothing,and even didn't give me an error message.
>>> I thought the compiler was broken but when I compile a normal
>>> D file it can work.
>>> I've also tried `dmd a.d b.c` and of course it didn't work
>>> too.
>>>
>>> Who knows why? I'm waiting for your answer.
>>
>> Which D compiler, and version?
>
> I used DMD 2.110.1 when compiling. Now I know it should be able
> to compile C files.
2.110.1 does not exist. Where did you get this compiler from?
Make sure you only install official compilers.
https://dlang.org/changelog/index.html
When I use 2.111.0, it does work for me:
```
steves at homebuild:~$ dmd --version
DMD64 D Compiler v2.111.0
Copyright (C) 1999-2025 by The D Language Foundation, All Rights
Reserved written by Walter Bright
steves at homebuild:~$ cat hello.c
#include<stdio.h>
int main(){
printf("Hello World!\n");
return 0;
}
steves at homebuild:~$ dmd hello.c
steves at homebuild:~$ echo $?
0
steves at homebuild:~$ ./hello
Hello World!
steves at homebuild:~$
```
-Steve
More information about the Digitalmars-d-learn
mailing list