Reputation: 415
What is the D2 language equivalent of __declspec(dllexport)
I have the D2 DLL linkage example code up and running. Exporting functions, both in dmd's mangled name space as well as well as in standard u-mangled "C" name space, works like a charm. But I'm running into uncharted waters regarding the sharing of a (global) int Variable between DLL's as well as the main exe program... I've checked the DLL symbol table with depends22_x86 and while I made a point of using the export directive just before the Var's declaration, it does not show up in the DLL's table, while functions do. Can one export Varibles to be visible in a DLL with the Digital Mars dmd tool chain?
Upvotes: 7
Views: 403
Reputation: 23650
As a workaround, if exporting or importing global variables doesn't work, then write a wrapper function of the form
Type variable;
extern(C) Type * getGlobalVariable()
{
return &variable;
}
if you want to export from D to C.
Upvotes: 0
Reputation: 1497
This was a bug in the compiler (Bugzilla 10059). The following code should work now.
export __gshared int foo;
Upvotes: 1
Reputation: 2002
Maybe you can do what Ralph Tandetzky says but in a static module ctor. You won’t have to explicitely call any function, all symbols will be loaded. Maybe __gshared would be appreciate, too.
Upvotes: 0