Calling a D function from C
Michal Minich
michal.minich at gmail.com
Fri Nov 12 07:19:12 PST 2010
V Fri, 12 Nov 2010 16:14:30 +0100, Carlo wrote:
> 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?
You probably need to include phobos library in gcc command line.
More information about the Digitalmars-d-learn
mailing list