Interfacing D functions from Racket
This is how you can use a function written in D from a Racket script.
In a file called logc.d
:
import std.stdio;
extern(C)
void hello()
{
writeln("hi from D");
}
Compile to a shared library with:
$ ldc2 -shared -m64 logc.d
or with
$ dmd -shared -m64 -fPIC -defaultlib=libphobos2.so logc.d
Use the generated liblogc.so
(or liblogc.dylib
) from a Racket script:
Try the results:
> (logc-hello)
hi from D
This post is based on Call D from Ruby using FFI and tutorial using racket’s ffi