[Issue 22335] New: Exporting variables from DLLs is unusable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 25 12:07:51 UTC 2021


          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 at puremagic.com
          Reporter: maxsamukha at gmail.com


module dll;

export __gshared int x = 41;

extern(Windows) int DllMain(void*, uint, void*)
    return 1;


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

'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


More information about the Digitalmars-d-bugs mailing list