Linking with C on Windows
Mark Isaacson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 5 15:47:50 PDT 2014
I'm having a very difficult time figuring out exactly how to do
this. I've compiled my D code into a .obj file with dmd, but I
don't know what C compiler I should use (or if it makes any
difference). I've attempted to use MinGW gcc, which spits out .o
files, and Visual Studio, which does... something else.
My attempts to have either the MinGW linker or the Visual Studio
linker accept my D .objs have all failed.
I have tried both extern(C) and extern(Windows) in the D code,
and I'm not sure which of them is more appropriate.
In any case, this is the code I'm trying to compile:
dimpl.d:
extern(Windows) int square(int x) { return x^^2; }
ciface.c:
#include <assert.h>
int square(int x);
int main() {
assert(square(2) == 4);
return 0;
}
I compiled dimpl.d with: dmd -c dimpl.d
Not really sure where to go from here, though I'll post back if I
figure anything out. I'm more than willing to take whatever
answer I get here and add it to appropriate wiki/site pages :)
Thanks!
More information about the Digitalmars-d-learn
mailing list