Bug 281 – dmd generates the object code ld cannot link when working with templates

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2006-08-09T17:34:00Z
Last change time
2014-02-15T13:19:33Z
Keywords
link-failure
Assigned to
bugzilla
Creator
tbolsh

Comments

Comment #0 by tbolsh — 2006-08-09T17:34:41Z
try to compile the following code with dmd: import std.boxer; import std.stdio; class Test{ char []txt; this(char []txt) { this.txt = txt; } char []toString(){ return txt; } } void main(char [][]args){ Test t1 = new Test("test"); Box tb = box( t1 ); Test t2 = unbox!(Test) (tb); } It compiles fine, but ld generates following errors: [tbolsh]$ dmd TestBoxer gcc TestBoxer.o -o TestBoxer -m32 -lphobos -lpthread -lm TestBoxer.o(.gnu.linkonce.t_D3std5boxer27__T5unboxTC9TestBoxer4TestZ5unboxFS3std5boxer3BoxZC9TestBoxer4Test+0x1a): In function `_D3std5boxer27__T5unboxTC9TestBoxer4TestZ5unboxFS3std5boxer3BoxZC9TestBoxer4Test': TestBoxer.d: undefined reference to `_assert_3std5boxer' collect2: ld returned 1 exit status --- errorlevel 1 GDC compiles and links such a code fine.
Comment #1 by tbolsh — 2006-08-09T17:37:04Z
gdc -v prints gdc 0.19, using dmd 0.162
Comment #2 by tbolsh — 2006-08-10T08:47:35Z
workaround: if dmd is started with -release flag everything is fine. WORKS LIKE A CHARM. I still think this bug should be resolved, but its priority should be lowered significantly. Chris Nicholson-Sauls was proposing to have the std/boxer.d in local path and build with it - I did not check, but that may help too.
Comment #3 by sean — 2006-08-10T10:10:19Z
[email protected] wrote: > > It compiles fine, but ld generates following errors: > > [tbolsh]$ dmd TestBoxer > gcc TestBoxer.o -o TestBoxer -m32 -lphobos -lpthread -lm > TestBoxer.o(.gnu.linkonce.t_D3std5boxer27__T5unboxTC9TestBoxer4TestZ5unboxFS3std5boxer3BoxZC9TestBoxer4Test+0x1a): > In function > `_D3std5boxer27__T5unboxTC9TestBoxer4TestZ5unboxFS3std5boxer3BoxZC9TestBoxer4Test': > TestBoxer.d: undefined reference to `_assert_3std5boxer' This is a known issue with DMD. Basically, Phobos is built in release mode so these functions are not generated in the std.boxer object file. When you import std.boxer into your app and build with -debug set, the template code for std.boxer is built into the app itself, with references to the code it thinks is in Phobos (but isn't). Since DMD always links against phobos.lib regardless of whether the app has -debug set, what I do for pure template modules like std.boxer is build them with -debug set and link that code into the lib. This makes the assert code and such available if it's needed, and if not it simply won't be used. It's not ideal, but it's a reasonable workaround until something is done about this issue. Sean
Comment #4 by bugzilla — 2008-06-24T23:15:37Z
Works with dmd 1.031 and 2.015