Calling a D function from C

Carlo carlo.lucibello at gmail.com
Fri Nov 12 07:14:30 PST 2010


Sorry if I bother you again with this probably silly problem. Here is 
the point. I want to call the D function "fun" from a .c file:

\\file libforc.d
extern (C) int fun(int x,int y){
         return x;
}
\\EOF

\\file ctest.c
#include <stdio.h>

int fun(int,int);

int main(int argc, char* argv[])
{
      printf("%d",fun(2,3));

      return 0;
}
\\EOF

This what I get trying to compile the .c file:

$ dmd libforc.d -c
$ gcc libforc.o ctest.c -m32
libforc.o: In function `no symbol':
libforc.d:(.text+0x8): undefined reference to `_Dmodule_ref'
collect2: ld returned 1 exit status

What did I miss?


More information about the Digitalmars-d-learn mailing list