export keyword messes up static linking

torhu fake at address.dude
Fri Jan 26 11:34:24 PST 2007


torhu wrote:

> from http://www.digitalmars.com/d/attribute.html :
> "Export means that any code outside the executable can access the 
> member. Export is analogous to exporting definitions from a DLL."
> 
> This is all that's written about export, apart from some examples on the 
> pages about DLL's and '.h to .d'.  They mostly show  that export is also 
> used for importing definitions from a DLL, not just exporting.
> 
> Just putting this on top of the file seems to work with dmd on windows, 
> at least after some preliminary testing:
> 
> version (STATICLINK) {}
> else export:
> 
> I didn't think of using export with a colon, but it seems the best 
> alternative to search and replace.  Can I safely assume that if I have a 
> definition in the D code that is declared export (but not extern), it 
> will still be a definition?  That seems to be the idea, but I don't feel 
> entirely safe.
> 
> The other way, leaving out 'export' for symbols that are imported from 
> the DLL when doing dynamic linking actually works for some symbols but 
> not others, which is a bit scary.  It's not needed for functions, just 
> for variables.

'export:' at the top of the files seems to work.  Except for one thing. 
  Imported functions that are declared like this only partially work:

export extern (C) int f(float x);

The export makes them it impossible to use their address in static 
initialization.  This doesn't compile:

extern (C) int (*proc)(float) = &f;


So I still think a suitable .def file might be a cleaner solution.


More information about the Digitalmars-d-learn mailing list