d and c

Ellery Newcomer ellery-newcomer at utulsa.edu
Tue Aug 31 19:47:21 PDT 2010


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);
}

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

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?


More information about the Digitalmars-d-learn mailing list