September 25, 2021 [Issue 22335] New: Exporting variables from DLLs is unusable | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=22335 Issue ID: 22335 Summary: Exporting variables from DLLs is unusable Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: maxsamukha@gmail.com dll.d: module dll; export __gshared int x = 41; extern(Windows) int DllMain(void*, uint, void*) { return 1; } ---- client.d: module client; import dll; void main() { assert(x == 41); // fails. x refers to garbage } ---- dmd -m64 -shared dll.d dmd -m64 client.d dll.lib client.exe 'dmd -m64 -H -o- dll.d' emits the definition instead of declaration, so using the interface file is not an option either. The only way to make this work is to manually change the definition in the .di file to the declaration ('extern export __gshared int x'), which is impractical. -- |
Copyright © 1999-2021 by the D Language Foundation