Using D libs in C

GreatEmerald pastas4 at gmail.com
Mon Feb 7 07:28:41 PST 2011


Everything is right from what I can tell. This is the code I use for the D part:

module dpart;
import std.c.stdio;

extern(C):

    shared int ResultD;

    int Process(int Value)
    {
        printf("You have sent the value: %d\n", Value);
        ResultD = (Value % 5);
        return ResultD;
    }

And the C part:

#include <stdio.h>
extern int ResultD;
int Process(int Value);

int main()
{
	printf("Sending 3...\n");
	Process(3);
	printf("The result is %d\n", ResultD);
	getchar();
	return 0;
}

This is pretty much the same thing as in the Windows version, just with scanf()
omitted.

Jacob, in Windows I am required to explicitly tell DMD to compile phobos.lib, but
not in Linux. Quite odd.


More information about the Digitalmars-d-learn mailing list