I went through http://dlang.org/cpp_interface.html and in all the examples, even those where some C ++ code calls some D code, the main function is in D (and therefore the binary code compiled from the source file is called D) The example of “calling D from C ++” in the doc document has a function foo defined in D that is called from the function bar in C ++, and bar, in turn, is called from the main function in D.
Is it possible to just call D code from a C ++ function? I am trying to do something simple as shown below, but keep creating build errors:
In D:
import std.stdio;
extern (C++) void CallFromCPlusPlusTest() {
writeln("You can call me from C++");
}
Then in C ++:
#include <iostream>
using namespace std;
void CallFromCPlusPlusTest();
int main() {
cout << "hello world"<<"\n";
CallFromCPlusPlusTest();
}
source
share