[Issue 1830] duplicated constants + extern(Windows) = Link error: Previous Definition Different

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 13 15:52:29 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1830





------- Comment #4 from torhu at yahoo.com  2008-02-13 17:52 -------
(In reply to comment #3)
> A) Why should the name mangling affect whether the linker says it is a
> multiply-defined symbol?  

The regular D name mangling convention adds the module name to the beginning of
the mangled symbol, and the type at the end.

If FOO in your module was extern (D), it would be mangled as '_D6link_a3FOOk'. 
For the other module, _D6link_b3FOOk.  So there is no conflict when linking.

With C name mangling on Windows, it's just _FOO in both cases.  That's why the
linker complains.

To work around this, you can avoid linking with both modules.  Since they only
define an integer constant, you don't even need to link with any of them.  Try
it. :)

Compiling one or both module into .lib files will work too, at least for your
sample and other simple cases.

> 
> B) The error message says specifically "previous definition different" which is
> simply untrue.  The previous definition was identical.
> 

Might be a linker bug, I don't know.  I doesn't matter if they identical or
not, they can't have the same mangled name.

> C) Your workaround #1 is self-contradictory - you say change extern(Windows) to
> extern(D), but then later say extern(Windows) is correct for these symbols.
> 
No, I just meant that C mangling is correct when using extern (Windows).

> D) Your workaround #2 (change const to enum) requires a change to Phobos,
> meaning that at the very least this is a bug against Phobos whose
> std.c.windows.windows module uses const rather than enum.
> 

I'll agree with that.  The title is probably wrong then.


-- 



More information about the Digitalmars-d-bugs mailing list