使用 dmd 编译 D2 语言时如何从 DLL 导出变量?

发布于 2024-12-26 17:34:33 字数 379 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世态炎凉 2025-01-02 17:34:33

这是编译器中的一个错误 (Bugzilla 10059)。
下面的代码现在应该可以工作了。

export __gshared int foo;

This was a bug in the compiler (Bugzilla 10059).
The following code should work now.

export __gshared int foo;
猫瑾少女 2025-01-02 17:34:33

也许你可以按照 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.

最笨的告白 2025-01-02 17:34:33

作为解决方法,如果导出或导入全局变量不起作用,请编写以下形式的包装函数(

Type variable;

extern(C) Type * getGlobalVariable()
{
    return &variable;
}

如果您想从 D 导出到 C)。

As a workaround, if exporting or importing global variables doesn't work, then write a wrapper function of the form

Type variable;

extern(C) Type * getGlobalVariable()
{
    return &variable;
}

if you want to export from D to C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文