Using C header libs with importC

Renato renato at athaydes.com
Mon Jan 8 21:56:10 UTC 2024


On Monday, 8 January 2024 at 21:04:10 UTC, Dennis wrote:
> On Monday, 8 January 2024 at 18:53:47 UTC, Renato wrote:
>> Perhaps using an intermediate C file to do this would work, 
>> but I wanted to know if D can do it.
>
> Yes, your best options are either:
>
> - rename the .h to .c and edit it so the 
> `STB_DS_IMPLEMENTATION` check passes or is removed.
> - create a C file with what you already wrote:
>
>> ```c
>> #define STB_DS_IMPLEMENTATION
>> #include "stb_ds.h"
>> ```
>
> And import that.

You answered almost at the same time as I sent my previous 
answer, so I hadn't seen your comment, but I tried exactly that! 
Which gives a seg fault.

I also tried just importing this little C file, but then no 
symbols from the h file are found at all. Kind of interesting, as 
if I just write the code using the library in the C file itself, 
that works fine.

> Importing .h files from d files isn't supported yet because of 
> a dispute with the lookup priority:
>
> https://issues.dlang.org/show_bug.cgi?id=23479
> https://issues.dlang.org/show_bug.cgi?id=23547

Ah, too bad. Anyway, I was just playing around... disappointing 
that it doesn't work but I don't really need this for now.



More information about the Digitalmars-d-learn mailing list