Calling D from C
There's very little new to bring to the table when discussing how to call D from C. On the D side, any functions and global variables that should be available for C should be declared extern(C)
. You could use extern(Windows)
or extern(System)
for special cases, but generally extern(C)
is what you want. On the C side, all that needs to be done is to create a standard C header with the appropriate type declarations and function prototypes, or global variables. As long as the linkage attributes are correct, any C code linked with the D code will think it's talking to C.
At the time of writing, shared library support for DMD is not complete. It isn't implemented at all on OS X. Now and again, someone asks for help in the forums when having trouble compiling shared libraries on other platforms. In the interest of saving space, we won't cover how to build them here. You can find information on how to compile shared libraries with DMD on Windows at http://wiki.dlang.org/Win32_DLLs_in_D...