ImportC + -H = bindings
Lance Bachmeier
no at spam.net
Fri Apr 24 02:09:00 UTC 2026
On Friday, 24 April 2026 at 01:09:28 UTC, Kapendev wrote:
> I recently made a script/library called
> [Clonoa](https://github.com/Kapendev/clonoa) that generates D
> bindings from C files using ImportC.
> The way it works is really simple:
>
> 1. Runs: `compiler -o- -H file.c`
> 2. Parses the `.di` file from the command above and prints a
> cleaned version of it to stdout.
>
> The generated output tries to avoid some redefinitions of Libc
> symbols and it assumes that names starting with `_` are always
> private, so they get skipped.
> Overall it does a good job of including the right things.
> For example, I was able to create bindings for SDL2 and use
> them.
>
> To use the script via DUB, you can run:
>
> ```
> dub run clonoa
> ```
>
> Or even simpler, copy-paste the script into your own project.
> Clonoa is just one D file.
I'm not sure how it compares to clonoa, but I let ImportC do the
translation of C headers in their entirety using the -Hf switch.
Now, that isn't going to generate .di files that work, but I have
a program that parses the files to remove duplicate definitions,
functions with keywords as names, and whatever else doesn't work.
It's at the point that it can automatically convert any C header
I try.
More information about the Digitalmars-d
mailing list