3
自从我尝试从C++调用一些D代码(为C++和D定义类/接口)以来。C++到D的互操作性
的d代码
module BufferCppBinding;
extern (C++) void *createBufferCppBinding() {
BufferCppBinding ptr = new BufferCppBinding();
return cast(void*)ptr;
}
extern (C++) interface BufferCppBindingInterface {
void construct();
// ...
}
class BufferCppBinding : BufferCppBindingInterface {
public Buffer thisPtr;
public extern (C++) void construct() {
// doesn't do anything
}
}
用于声明类型C++土地C++代码:
class BufferCppBinding {
public:
virtual void construct();
};
为d的运行时的初始化i的d,其确实在d写了一个小的功能土地:
extern (C++) void initDRuntime() nothrow{
try
{
Runtime.initialize();
//result = myWinMain(hInstance, hPrevInstance, lpCmdLine, iCmdShow);
//Runtime.terminate(&exceptionHandler);
}
catch (Throwable o)
{
//MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | MB_ICONEXCLAMATION);
//result = 0;
}
}
使用(C++):
BufferCppBinding *vertexBuffer = reinterpret_cast<BufferCppBinding*>(createBufferCppBinding());
// here happens the crash
vertexBuffer->construct();
我正在用g ++ 5.2和ldc2编译代码并将它与ldc2链接起来。
我刚刚得到一个SIGSEGV。
如果你在C++中的声明是D接口(BufferCppBindingInterface)的声明? http://dlang.org/cpp_interface.html – TractorPulledPork