D modules referenced by C source?
robert at octarineparrot.com
Thu May 7 14:17:29 PDT 2009
> Hi, I apologise if this has already been asked, but I haven't gone and DLed a news reader yet, so Firefox keeps complaining every time I try to use the search box.
> I was planning to include some C source into a D project, and was happily writing the D module for the "header" for the source, when I ran into a little problem. I want to include some const values in the module, which made me realize I don't know how to include the module in the C source. I can see how it would work from the D side of the compilation, but how would I go about making the const values visible to the C code? Do I just #include "d_module.d"? Or is there a different way to do this? What would the compilation process look like for this?
> Thank you in advance for any help you can provide.
I've never tried this, but I guess you'd do something like:
extern(C) void myFunction();
In the D file, compile it, then link the resulting object in when you
compile the C app. You would of course need to define this function and
anything else you've extern(C)'d in the C app so it's available. I'm
guessing that you wouldn't be able to use a large chunk of D's
functionality without linking in a good chunk (if not all) of a D
runtime too, but I may be wrong.
More information about the Digitalmars-d