Bug 22603 – __gshared doesn't imply 'static' when linking against C++

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2021-12-15T23:03:26Z
Last change time
2024-12-13T19:19:54Z
Assigned to
No Owner
Creator
Jan
Moved to GitHub: dmd#20024 →

Comments

Comment #0 by jan — 2021-12-15T23:03:26Z
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++.
Comment #1 by robert.schadek — 2024-12-13T19:19:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20024 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB