Thread overview
Link error with template struct on 2.042
Mar 31, 2010
Frank Fischer
Mar 31, 2010
Regan Heath
Mar 31, 2010
Frank Fischer
Mar 31, 2010
Regan Heath
Mar 31, 2010
Jacob Carlborg
Mar 31, 2010
Frank Fischer
March 31, 2010
Hi,

after some time I started again playing with D. The following example gives an error I don't understand (I'm trying dmd 2.042):

==== main.d ====
import MyMod;

void main()
{
    MyStruct!(int) s;
}

==== MyMod.d ===
module MyMod;

struct MyStruct(T) {
    this(this) {}
}
================

If I compile the above example with

dmd main.d

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.

Thanks in advance
Frank

March 31, 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
March 31, 2010
On 3/31/10 09:26, Frank Fischer wrote:
> Hi,
>
> after some time I started again playing with D. The following example
> gives an error I don't understand (I'm trying dmd 2.042):
>
> ==== main.d ====
> import MyMod;
>
> void main()
> {
>      MyStruct!(int) s;
> }
>
> ==== MyMod.d ===
> module MyMod;
>
> struct MyStruct(T) {
>      this(this) {}
> }
> ================
>
> If I compile the above example with
>
> dmd main.d
>
> 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.
>
> Thanks in advance
> Frank
>

I don't know if I'm missing something but don't you have to compile MyMod.d also ?
March 31, 2010
On 2010-03-31, Regan Heath <regan@netmail.co.nz> wrote:
> Frank Fischer wrote:
>> If I compile the above example with
>> 
>> dmd main.d
>
> Weird, that command line works fine for me, no errors.
>

Strange. I used the linux version 2.042, just downloaded.

> 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?

Yes, exactly those two files. Nothing more, nothing less. The example also works if I put the struct in the file main.d.

Frank

March 31, 2010
On 2010-03-31, Jacob Carlborg <doob@me.com> wrote:
> I don't know if I'm missing something but don't you have to compile MyMod.d also ?

Of course, you're right. Don't know why I expected dmd to compile the other files as well, propably because it worked without the this(this) function.

I'm really happy it was only my stupidity ;)

Thanks,
Frank

March 31, 2010
Frank Fischer wrote:
> On 2010-03-31, Regan Heath <regan@netmail.co.nz> wrote:
>> Frank Fischer wrote:
>>> If I compile the above example with
>>>
>>> dmd main.d
>> Weird, that command line works fine for me, no errors.
>>
> 
> Strange. I used the linux version 2.042, just downloaded.

Ahh.. I am on Windoze.. interesting.

R