Using C header libs with importC

Lance Bachmeier no at spam.net
Mon Jan 8 19:17:06 UTC 2024


On Monday, 8 January 2024 at 18:53:47 UTC, Renato wrote:
> Is it possible to use C header-only libs from D?
>
> In C, I would need to do this:
>
> ```c
> #define STB_DS_IMPLEMENTATION
> #include "stb_ds.h"
> ```
>
> The definition must be done in a single C file before including 
> the h file.
>
> I tried this in D:
>
> ```d
> enum STB_DS_IMPLEMENTATION = 1;
> import stb_ds;
> ```
>
> But it doesn't work. Any suggestions? Perhaps using an 
> intermediate C file to do this would work, but I wanted to know 
> if D can do it.

Without knowing the specifics of what you're trying to do, this 
automatic translation of C headers to D might be what you want:

https://forum.dlang.org/post/ugvc3o$5t3$1@digitalmars.com

The way "header-only" is usually used suggests you should change 
the file extension to .c and compile it directly.


More information about the Digitalmars-d-learn mailing list