www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22603] New: __gshared doesn't imply 'static' when linking


          Issue ID: 22603
           Summary: __gshared doesn't imply 'static' when linking against
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jan krassnigg.de

Using this C++ code:

class Test
  __declspec(dllexport) static int var;

int Test::var = 42;

You should be able to link against it, using this D declaration:

extern(C++, class) struct Test
  extern export __gshared int var;

The __gshared should imply that that the variable is static. However, this will
give a linker error, instead you have to use:

extern(C++, class) struct Test
  extern export static __gshared int var;

Also, it would be very helpful, if the D documentation page would mention
linking against global/static variables at all
(https://dlang.org/spec/cpp_interface.html#data-type-compatibility), since the
'static' keyword doesn't map directly between D and C++.

Dec 15 2021