<div>I'm trying to set up a project where I can call D functions from C code. Based on the documentation (<a href="http://www.digitalmars.com/d/2.0/interfaceToC.html">http://www.digitalmars.com/d/2.0/interfaceToC.html</a>) it looks like I should be able to do the following:</div>
<div><br></div>dee.d:<div>- - - - - - - -<br><div><div>import std.stdio;</div><div><br></div><div><div>extern(C)</div><div>{</div><div> void sayHelloFromD()</div><div> {</div><div> writeln("Hello from D.");</div>
<div> }</div><div>}</div></div><div>- - - - - - - -</div><div><br></div><div><br></div><div>dee.h</div><div>- - - - - - - -</div><div><div>void sayHelloFromD();</div></div><div>- - - - - - - -</div><div><br></div><div>
<br></div><div>cee.c</div><div>- - - - - - - -</div><div>#include <stdio.h></div><div><div>#include "dee.h";</div><div><br></div><div>int main()</div><div>{</div><div> printf("Hello from C.\n");</div>
<div> sayHelloFromD();</div><div> return 0;</div><div>}</div></div><div>- - - - - - - -</div><div><br></div></div><div><br></div><div>To compile:</div><div>dmd -c dee.d</div><div>gcc dee.o cee.c -arch i386 -o hello</div>
<div><br></div><div>It fails with the following:</div><div><div>Undefined symbols:</div><div> "_D3std5stdio6stdoutS3std5stdio4File", referenced from:</div><div> _D3std5stdio6stdoutS3std5stdio4File$non_lazy_ptr in dee.o</div>
<div> (maybe you meant: _D3std5stdio6stdoutS3std5stdio4File$non_lazy_ptr)</div><div> "_D15TypeInfo_Struct6__vtblZ", referenced from:</div><div> _D47TypeInfo_S3std6traits15__T8DemangleTkZ8Demangle6__initZ in dee.o</div>
<div> "_D3std9contracts7bailOutFAyaixAaZv", referenced from:</div><div> _D3std9contracts112__T7enforceTbVAyaa42_2f6f70742f646d64322f62696e2f2e2e2f2e2e2f7372632f70686f626f732f7374642f737464696f2e64Vi1332Z7enforceFbLAxaZb in dee.o</div>
<div> "_D3std5stdio12__ModuleInfoZ", referenced from:</div><div> _D3dee12__ModuleInfoZ in dee.o</div><div>ld: symbol(s) not found</div><div>collect2: ld returned 1 exit status</div></div><div><br></div><div>
<br></div><div>I would appreciate any help you can give me with this.</div><div><br></div><div>Daniel</div></div>