digitalmars.D.bugs - [Issue 22603] New: __gshared doesn't imply 'static' when linking
- d-bugmail puremagic.com (43/43) Dec 15 2021 https://issues.dlang.org/show_bug.cgi?id=22603
https://issues.dlang.org/show_bug.cgi?id=22603 Issue ID: 22603 Summary: __gshared doesn't imply 'static' when linking against C++ 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 { public: __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