www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22335] New: Exporting variables from DLLs is unusable


          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


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

Sep 25 2021