Bug 1629 – Link error: Previous Definition Different: blablah__initZ
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-10-31T03:02:00Z
Last change time
2014-02-24T15:33:10Z
Keywords
link-failure
Assigned to
bugzilla
Creator
wbaxter
Comments
Comment #0 by wbaxter — 2007-10-31T03:02:34Z
The error seems to require a sort of a diamond pattern of imports. So it takes several files to get it to happen. Here's the minimal I've been able to get so far:
---link_main.d---
module link_main;
import link_a;
import link_b;
link_a.Thing thinga;
link_b.Thing thingb;
void main()
{
}
---link_a.d---
module link_a;
import link_common;
alias link_common.CommonThing!() Thing;
---link_b.d---
module link_b;
import link_common;
alias link_common.CommonThing!() Thing;
---link_common.d---
module link_common;
import link_default;
struct CommonThing(T = DefaultT)
{
struct InnerT {
alias DefaultT.Type Type;
}
const ConstValue = DefaultT.ConstValue;
}
---link_default.d--
module link_default;
struct DefaultT
{
alias float Type ;
const uint ConstValue = 0;
}
---
Here's the exact compilation error:
rebuild -oqobjs link_main
f:\usr\pkg\d\dmd\bin\..\..\dm\bin\link.exe objs\_link_main+objs\_link_a+objs\_link_common+objs\_link_default+objs\_link_b,link_main.exe,,user32+kernel32/noi;
OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
objs\_link_b.obj(_link_b) Offset 001ADH Record Type 0091
Error 1: Previous Definition Different : _D11link_common17__T11CommonThingZ11CommonThing6InnerT6__initZ
--- errorlevel 1
At least in my actual case where this came up I found I could make the problem go away if I created yet another module that link_a and link_b import that looks like:
public import link_common;
alias link_common.CommonThing!() Thing;
This seems to clue the linker in that the two aliases are really instantiations of the same template.
Note that the repro case uses 'rebuild' for compiling. It happens to use version 0.73, which has the compile-one-file-at-a-time behavior that Gregor put in to fix another linking error.
The compilation works fine with dmd passing all files at once, the compiling separately one-at-a-time is what causes the failure.
Comment #3 by matti.niemenmaa+dbugzilla — 2008-07-19T08:35:21Z
Just ran into this with Tango's XML package (tango.text.xml.DocPrinter to be exact).This one's a bit different though, as one needs -inline and -release thrown to trigger it.
Minimal testcase follows. Three files, no diamond pattern of imports, just a straight line:
---------------------------
a.d:
----
module a;
import b;
void main() {}
b.d
---
module b;
import c;
// works - even fixes the error from below!
// C!(int) x;
// doesn't work
void foo() { C!(int) x; }
c.d
---
module c;
class C(T) { struct X {} }
---------------------------
Compile separately and link:
dmd -c a.d -inline -release
dmd -c b.d -inline -release
dmd -c c.d -inline -release
dmd a.obj b.obj c.obj
And get:
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
b.obj(b) Offset 0014EH Record Type 0091
Error 1: Previous Definition Different : _D1c8__T1CTiZ1C1X6__initZ
--- errorlevel 1
Note the comment in b.d: adding an instantiation (or alias, thanks to the original reporter for that hint) at global scope fixes the problem.
Comment #4 by bugzilla — 2009-03-11T14:51:49Z
Fixed dmd 1.041 and 2.026
Comment #5 by clugdbug — 2009-09-04T07:03:36Z
*** Issue 2530 has been marked as a duplicate of this issue. ***