【发布时间】:2012-03-18 12:24:04
【问题描述】:
我正在尝试使用 D 中的动态共享库快速入门,但遇到了问题。
我正在使用dmd -shared ./testlib.d 构建以下代码:
module testlib;
import std.c.stdio;
extern (C) export int hello(int a) {
printf("Number is %d", a);
return (a + 1);
}
它构建良好,并且工作正常。但是当我尝试使用以下更多 D'ish 来源时:
module testlib;
import std.stdio;
extern (C) export int hello(int a) {
writefln("Number is %d", a);
return (a + 1);
}
一旦我尝试调用hello,它就会因分段错误而失败。我做错了什么?
我正在使用 Python 调用 hello:
import ctypes
testlib = ctypes.CDLL('testlib.dylib');
print (testlib.hello(10))
UPD1:好像我也不能使用像std.conv.to!(string)这样的Phobos功能。
UPD2: 在 Windows 上没有这样的问题,一切似乎都运行良好。 Mac OS X 也受此困扰。
UPD3:这可能与GC有关。我必须以某种方式初始化 GC,但 core.memory.GC.enable() 仍然因分段错误而失败。
【问题讨论】:
标签: shared-libraries d