Using D libs in C

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Jan 16 13:32:39 PST 2011


Of course!

dstatic.d:
module dstatic;

extern(C):

int add(int x, int y)
{
    return x + y;
}

Then compile with:
dmd -lib dstatic.d

driver.c:
#include "stdio.h"

int main()
{
    printf("add(4, 5) = %d", add(4, 5));
}

dmc driver.c dstatic.lib

driver.exe
> add(4, 5) = 9


More information about the Digitalmars-d-learn mailing list