www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 281] New: dmd generates the object code ld cannot link when working with templates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=281

           Summary: dmd generates the object code ld cannot link when
                    working with templates
           Product: D
           Version: 0.163
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: link-failure
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: tbolsh gmail.com


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.


-- 
Aug 09 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=281





------- Comment #1 from tbolsh gmail.com  2006-08-09 17:37 -------
gdc -v 

prints

gdc 0.19, using dmd 0.162


-- 
Aug 09 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=281


tbolsh gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tbolsh gmail.com
           Severity|major                       |minor
           Priority|P2                          |P3




------- Comment #2 from tbolsh gmail.com  2006-08-10 08:47 -------
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.


-- 
Aug 10 2006
prev sibling next sibling parent Sean Kelly <sean f4.ca> writes:
d-bugmail puremagic.com 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
Aug 10 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=281


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME




------- Comment #4 from bugzilla digitalmars.com  2008-06-24 23:15 -------
Works with dmd 1.031 and 2.015


-- 
Jun 24 2008