On Monday, 16 February 2026 at 20:06:52 UTC, Lance Bachmeier wrote:
On Monday, 16 February 2026 at 20:04:36 UTC, Lance Bachmeier wrote:
On Monday, 16 February 2026 at 17:07:53 UTC, MaxNaderer wrote:
Hello guys,

so how do we generate C header files automatically for a library compiled with dmd, ldc in betterC. Like basic example below. I found the "-HC" flag which can be used to output C++ header files. Do I need to convert those manually to C?

```D

export extern(C) {

    uint add(uint a, uint b) {
        return a + b;
    }

}

```
dmd -c mycode.c -Hf=mycode.di
```

https://dlang.org/spec/importc.html#ctod

If you want to output the function bodies as D code, add `-inline`:

```
dmd -c mycode.c -inline -Hf=mycode.di
```

Oh sorry. I think you mean you are compiling D code to be called from C.

Thank you for your answer. Yes I am going the other way. I create the lib in D and want to create a C header and other bindings. It should be a lib usable from many other languages like raylib but with the power of D!

I have looked into __traits and I guess i need to go this way.
The perfect way would be to get a XML or json from the functions so that the bindings can be easily automated

Reply via email to