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