writing pure C program with dmd / linking error

Matthias Walter walter at mail.math.uni-magdeburg.de
Sun Mar 11 10:45:22 PDT 2007


I'm trying to write a pure C program with D, like:

extern (C) {

int main(int argc, char **argv) {
        return 1;
}

}

I did:
dmd -c test.d
gcc -o test test.o

the linker complains: 
test.o: In function `gcc2_compiled.':
test.d:(.text+0x8): undefined reference to `_Dmodule_ref'

I need this, as I want to write a library, which contains C and D, so it must be linkable with a simple c object file. Of course, in this case, I could have simply written it as a c file, but my library seams to need it, too. The symbol is in libphobos.a, but my library should not include / link against phobos.

Is it possible, to turn off generation of this reference? Is it very important for things to work?

Or is it even impossible to create libraries with C and D? 

What about writing C programs the way I did to benefit from all those compiler features like version syntax, DDoc, contract programming, etc.

I'm running Linux on x86 with dmd-1.009 and gcc-4.1.1


More information about the Digitalmars-d-learn mailing list