Creating a .di file for a custom C library

evilrat evilrat666 at gmail.com
Tue Mar 30 07:39:04 UTC 2021


On Tuesday, 30 March 2021 at 04:01:12 UTC, Brad wrote:
> I would like to use an updated version of the Termbox library 
> (written in C) with D.  I have the .h file.  This is new 
> territory for me (why try something easy - right?).  I think I 
> need to create a .di file that corresponds to the .h file.  I 
> also suspect that I need to put the library file (C code) into 
> the project as a file somehow.  I am probably just not looking 
> in the right place for the documentation, but I cannot seem to 
> find a lot of guidance in this area.
>
> Thanks in advance.

No just convert C signatures to corresponding D signatures in 
regular .d file.
Then you need to build original C library, and then when building 
D program you link(pass produced .lib/.a files to 
compiler/linker) this stuff with C library.

After all your binaries is just language agnostic bytes, however 
there is calling conventions that exist for interop, your .h 
contains definitions (aka contract) of what it does, and produced 
binaries (.exe, .a, .lib, .dll, .so) contains actual machine 
code, so on D side you must match that contract and then tell the 
linker to embed the machine code from .a/.lib in your final 
executable/DLL.


More information about the Digitalmars-d-learn mailing list