Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 07, 2004 separate compilation and repeated definitions | ||||
---|---|---|---|---|
| ||||
I'm wondering how to work around a linking issue involving templates and separate compilation. I have three files temp1.d temp2.d and temp3.d: module temp1; struct Foo(T) { void set(T x) { y = x; } T y; } module temp2; import temp1; void t2() { Foo!(int)* x; x = new Foo!(int); x.set(10); } module temp3; import temp1; import temp2; void t3() { Foo!(int)* x; x = new Foo!(int); x.set(100); } int main() { t2(); t3(); return 0; } Now if I run dmd temp1.d temp2.d temp3.d then everything works fine. But if I run dmd -c temp1;d dmd -c temp2.d dmd -c temp3.d dmd temp1.obj temp2.obj temp3.obj I get: C:\d>dmd temp1.obj temp2.obj temp3.obj C:\dmd\bin\..\..\dm\bin\link.exe temp1+temp2+temp3,,,user32+kernel32/noi; OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved temp3.obj(temp3) Offset 001C7H Record Type 00C3 Error 1: Previous Definition Different : _D5temp15Foo_i3Foo3setFiZv --- errorlevel 1 Is this going to be a fact of life involving templates? Or is this a temporary state? I can redo my MinTL makefiles to always list everything on one command line when building unittests. I'm not sure if it will come up elsewhre. I'll have to check that none of my libraries contain template instantiations that could end up conflicting with user code. It basically makes separate compilation incompatible with templates unless you are very careful to never mix object files that could share a template instantiation. -Ben |
December 07, 2004 Re: separate compilation and repeated definitions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | This shouldn't happen. I would consider it a bug. Sean |
December 12, 2004 Re: separate compilation and repeated definitions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle Attachments: | Added to DStress: http://svn.kuehne.cn/dstress/complex/linking/ all 3 in one step: make complex/linking/linking_01 3 in 3 steps: make complex/linking/linking_02 Thomas Ben Hinkle schrieb am Mon, 6 Dec 2004 20:04:51 -0500: > I'm wondering how to work around a linking issue involving templates and separate compilation. I have three files temp1.d temp2.d and temp3.d: > > module temp1; > struct Foo(T) { > void set(T x) { y = x; } > T y; > } > > module temp2; > import temp1; > void t2() { > Foo!(int)* x; > x = new Foo!(int); > x.set(10); > } > > module temp3; > import temp1; > import temp2; > void t3() { > Foo!(int)* x; > x = new Foo!(int); > x.set(100); > } > int main() { > t2(); > t3(); > return 0; > } > > Now if I run > dmd temp1.d temp2.d temp3.d > then everything works fine. But if I run > dmd -c temp1;d > dmd -c temp2.d > dmd -c temp3.d > dmd temp1.obj temp2.obj temp3.obj > I get: > C:\d>dmd temp1.obj temp2.obj temp3.obj > C:\dmd\bin\..\..\dm\bin\link.exe temp1+temp2+temp3,,,user32+kernel32/noi; > OPTLINK (R) for Win32 Release 7.50B1 > Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved > > temp3.obj(temp3) Offset 001C7H Record Type 00C3 > Error 1: Previous Definition Different : _D5temp15Foo_i3Foo3setFiZv > --- errorlevel 1 > > Is this going to be a fact of life involving templates? Or is this a temporary state? I can redo my MinTL makefiles to always list everything on one command line when building unittests. I'm not sure if it will come up elsewhre. I'll have to check that none of my libraries contain template instantiations that could end up conflicting with user code. It basically makes separate compilation incompatible with templates unless you are very careful to never mix object files that could share a template instantiation. |
December 12, 2004 Re: separate compilation and repeated definitions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 >> Now if I run >> dmd temp1.d temp2.d temp3.d >> then everything works fine. But if I run >> dmd -c temp1;d >> dmd -c temp2.d >> dmd -c temp3.d >> dmd temp1.obj temp2.obj temp3.obj >> I get: >> C:\d>dmd temp1.obj temp2.obj temp3.obj >> C:\dmd\bin\..\..\dm\bin\link.exe temp1+temp2+temp3,,,user32+kernel32/noi; >> OPTLINK (R) for Win32 Release 7.50B1 >> Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved >> >> temp3.obj(temp3) Offset 001C7H Record Type 00C3 >> Error 1: Previous Definition Different : _D5temp15Foo_i3Foo3setFiZv >> --- errorlevel 1 Just a word of warning: GDC successfully compiles them separately, but fails on the combined invocation.. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFBvMsk3w+/yD4P9tIRAs9FAKCGr08EE3ycewH4Vv+nef14zuRheQCgvY9W C2MFueVLNstEvqenobAg84A= =vfLw -----END PGP SIGNATURE----- |
Copyright © 1999-2021 by the D Language Foundation