[Issue 22603] New: __gshared doesn't imply 'static' when linking against C++
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 15 23:03:26 UTC 2021
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 at puremagic.com
Reporter: jan at 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++.
--
More information about the Digitalmars-d-bugs
mailing list