ex.cpp
#include <string>
const char* get_string() {
return "Hello from C++!";
}
ex.d
extern (C++) {
immutable(char)* get_string();
}
void main() {
import std.conv : to;
import std.stdio : writeln;
string s = to!string(get_string());
writeln(s);
}
And to compile:
g++ -c -o cpp.o ex.cpp
dmd ex.d cpp.o -L-lstdc++
./ex
It should print:
Hello from C++!
Top comments (0)