Link error with template struct on 2.042

Regan Heath regan at netmail.co.nz
Wed Mar 31 01:33:38 PDT 2010


Frank Fischer wrote:
> If I compile the above example with
> 
> dmd main.d

Weird, that command line works fine for me, no errors.

> I get the following error:
> 
> main.o: In function
> `_D5MyMod15__T8MyStructTiZ8MyStruct10__postblitMFZv':
> main.d:(.text._D5MyMod15__T8MyStructTiZ8MyStruct10__postblitMFZv+0x12):
> undefined reference to `_D5MyMod8__assertFiZv'
> main.o: In function
> `_D5MyMod15__T8MyStructTiZ8MyStruct8opAssignMFNcS5MyMod15__T8MyStructTiZ8MyStructZS5MyMod15__T8MyStructTiZ8MyStruct':
> main.d:(.text._D5MyMod15__T8MyStructTiZ8MyStruct8opAssignMFNcS5MyMod15__T8MyStructTiZ8MyStructZS5MyMod15__T8MyStructTiZ8MyStruct+0x12):
> undefined reference to `_D5MyMod8__assertFiZv'
> collect2: ld returned 1 exit status
> --- errorlevel 1
> 
> What does this mean? Note that everything works fine if MyStruct is
> not a template, if there's no function this(this) or if I compile the
> example with assertions disabled like this:
> 
> dmd -release main.d
> 
> It seems as I'm missing to implement some function, but I don't know
> which.

It is either implementing a function, or not calling one - sometimes 
debug mode will enable extra functions, I note the above undefined 
reference is to a symbol called MyMod.assert being called from 
MyStruct.opAssign.

Was that a complete code sample?

Regan


More information about the Digitalmars-d-learn mailing list