www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - d and c

Hello. Randomly bored tonight.

Motivated by this: 
http://stackoverflow.com/questions/3540596/mixing-c-and-d-code-in-the-same-program,

I was trying to get c to call d. I can't remember; is it actually possible?



64 bit Fedora and gcc; here's what I have:

$ cat test.d
import std.c.stdio;

extern(C){
     __gshared int x;

     void incx(){
         x++;
         printf("x is now %d\n", x);
     }
}

$ cat test2.c
#include <stdio.h>
extern int x;
void incx(void);

void main(void){
     printf("x: %d\n", x);
}


$ gcc -m32 -L/usr/lib/dmd-2.048/lib/ -ldruntime -lphobos2 test.o test2.c 


When I include druntime or phobos2, the linker complains that the symbol 
`main' is defined multiple times. When I don't include either, it 
complains that the symbol `_Dmodule_ref' is undefined.

help?
Aug 31 2010