problem creating a 32-bit dll

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 26 13:19:15 PDT 2014


On Tuesday, 26 August 2014 at 15:28:32 UTC, nezih wrote:
> I use optlink and I use the latest dmd: DMD32 D Compiler 
> v2.066.0
> And yes I see underscores in front of the exported symbol 
> names. What's the workaround? And I just verified that the 
> 64-bit version doesn't have those leading underscores.

Ah, runtime linking code rarely accounts for leading underscores 
(the so-called Windows "system" convention), so that is probably 
your problem.

First, make sure the symbols are marked extern(C) and not 
extern(Windows) or extern(System).

The workaround I usually use is simply prepending a dummy symbol 
to each exported one. If the exported C symbols are *not* mixed 
in, just manually place a dummy symbol at the beginning of the 
module:

---
export extern(C) void __optlinkdummy() {}
---

If they are mixed in through a mixin template or a string mixin, 
use pragma(mangle, ...) or string concatenation, respectively, to 
place a uniquely named dummy export before each proper export. 
This robustly ensures that your proper export is never the first 
exported symbol.

This is supposed to be fixed in the latest OPTLINK source code, 
so it's tragic that DMD 2.066 ships with an outdated version that 
still has this terrible bug :(


More information about the Digitalmars-d mailing list