Jump to page: 1 2
Thread overview
How to Use D's ImportC Compiler in a Program
Oct 06
Emmanuel
6 days ago
David T. Oxygen
6 days ago
David T. Oxygen
2 days ago
David T. Oxygen
2 days ago
jmh530
October 06

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.

October 06

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.

Hi,

can you show what's in your hello.c file ??

Thanks.

October 07

On Monday, Oct.6 2025 at 17:10:36 UTC, Emmanuel 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.
Hi,

can you show what's in your hello.c file ??

Thanks.
--
Nothing special.Just a simple Hello-World application.

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

Just like the example on the D website.

And what in it doesn't matter. The compiler didn't work,no matter what code.

I think if my compiler's version is too low to support ImportC...

October 06
On 10/6/25 5:56 PM, David T. Oxygen wrote:

> Nothing special.Just a simple Hello-World application.
> ```c
> #include<stdio.h>
> int main(){
>      printf("Hello World!\n");
>      return 0;
> }
> ```
> Just like the example on the D website.

I put that code into hello.c and compiled. Yes, there are some warning:

$ dmd hello.c
In file included from <command-line>:
/usr/include/dlang/dmd/importc.h:101:8: warning: undefining "__has_feature"
  101 | #undef __has_feature
      |        ^~~~~~~~~~~~~
/usr/include/dlang/dmd/importc.h:104:8: warning: undefining "__has_extension"
  104 | #undef __has_extension
      |        ^~~~~~~~~~~~~~~

I don't know what they mean. My compiler is this:

$ dmd --version
DMD64 D Compiler v2.109.1

But at least the linked program works:

$ ./hello
Hello World!

> And what in it doesn't matter. The compiler didn't work,no matter what
> code.

Which compiler? Were there any error messages?

> I think if my compiler's version is too low to support ImportC...

Possibly. As a reminder, here is the download page.

  https://dlang.org/download.html

Ali

October 07

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?

October 07

On Tuesday, 7 October 2025 at 00:56:26 UTC, David T. Oxygen wrote:
[...]

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

Compilable without errors or warnings, when dmd 2.111.0 and "Visual Studio" 2019 and 2026 are installed under win11.

6 days ago

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.

6 days ago

I think if it couldn't compile, at last it should warn me. But sadly, it not. It just did nothing.

6 days ago

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@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@homebuild:~$ cat hello.c
#include<stdio.h>
int main(){
    printf("Hello World!\n");
    return 0;
}
steves@homebuild:~$ dmd hello.c
steves@homebuild:~$ echo $?
0
steves@homebuild:~$ ./hello
Hello World!
steves@homebuild:~$

-Steve

2 days ago

On Wednesday, 8 October 2025 at 02:00:59 UTC, Steven Schveighoffer wrote:

> > > >

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@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@homebuild:~$ cat hello.c
#include<stdio.h>
int main(){
    printf("Hello World!\n");
    return 0;
}
steves@homebuild:~$ dmd hello.c
steves@homebuild:~$ echo $?
0
steves@homebuild:~$ ./hello
Hello World!
steves@homebuild:~$

-Steve
--
Thank you for your help,but I still haven't solved my problem.
I reinstalled DMD 2.111.0 today,it's the newest relaese version. However,the compiler still keep silent when compiling dmd hello.c...(If it can't compile,at last it should complain,all right? But it did nothing...)
But if I speak dmd --version it will tell me:
DMD64 D Compiler v2.111.0 Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved written by Walter Bright

And it can compile a normal D file which doesn't import a C file. If the D file imports a C file,the compiler will still keep silent...

Oh no that's too bad. I wonder if there may be anything wrong with my computer...

« First   ‹ Prev
1 2