使用 dmd 编译 D2 语言时如何从 DLL 导出变量?
相当于 __declspec(dllexport) 的 D2 语言是什么
What is the D2 language equivalent of __declspec(dllexport)
I have the D2 DLL linkage example code up and running. Exporting functions, both in dmd's mangled name space as well as well as in standard u-mangled "C" name space, works like a charm. But I'm running into uncharted waters regarding the sharing of a (global) int Variable between DLL's as well as the main exe program... I've checked the DLL symbol table with depends22_x86 and while I made a point of using the export directive just before the Var's declaration, it does not show up in the DLL's table, while functions do.
Can one export Varibles to be visible in a DLL with the Digital Mars dmd tool chain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是编译器中的一个错误 (Bugzilla 10059)。
下面的代码现在应该可以工作了。
This was a bug in the compiler (Bugzilla 10059).
The following code should work now.
也许你可以按照 Ralph Tandetzky 所说的去做,但是在静态模块 ctor 中。您不必显式调用任何函数,所有符号都将被加载。也许 __gshared 也会很感激。
Maybe you can do what Ralph Tandetzky says but in a static module ctor. You won’t have to explicitely call any function, all symbols will be loaded. Maybe __gshared would be appreciate, too.
作为解决方法,如果导出或导入全局变量不起作用,请编写以下形式的包装函数(
如果您想从 D 导出到 C)。
As a workaround, if exporting or importing global variables doesn't work, then write a wrapper function of the form
if you want to export from D to C.