Thread overview
Template linker problems
May 16, 2005
Nick
May 17, 2005
Thomas Kuehne
May 18, 2005
Nick
May 18, 2005
Thomas Kuehne
May 19, 2005
Nick
May 16, 2005
The following snippet compiles but refuses to link. I'm using 0.123 on Linux (also tested with 0.119.)

---- tst.d ----
:module tst;
:
:import std.stdio;
:
:import tmod;
:
:class A
:{
:  template Foo(T)
:    {
:      void Foo()
:	{
:	  writefln("Remove this line and everything works");
:	}
:    }
:}
:
:void main() {}

---- tmod.d ----
:module tmod;
:
:import tst;
:
:class B: A
:{
:  alias Foo!(B) foo;
:}

$ dmd -c tmod.d
$ dmd tst.d tmod.o
gcc tst.o tmod.o -o tst -lphobos -lpthread -lm -Xlinker
-L/mn/tid/teori-s1/mortennk/uhh___filerogslikt/software/lib
tmod.o(.gnu.linkonce.t_D3tst1A12Foo_C4tmod1B3FooFZv+0x16): In function
`_D3tst1A12Foo_C4tmod1B3FooFZv':
: undefined reference to `_arguments_Aa'
tmod.o(.gnu.linkonce.t_D3tst1A12Foo_C4tmod1B3FooFZv+0x1c): In function
`_D3tst1A12Foo_C4tmod1B3FooFZv':
: undefined reference to `_arguments_Aa'
collect2: ld returned 1 exit status
--- errorlevel 1

There are at least three ways to work around this: One is to remove the
writefln() from Foo, the second is to place class B in the same file as class A,
and the third is to compile with one command instead of two:
$ dmd tst.d tmod.d

Nick


May 17, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick schrieb am Mon, 16 May 2005 19:17:04 +0000 (UTC):
> The following snippet compiles but refuses to link. I'm using 0.123 on Linux (also tested with 0.119.)
>
> ---- tst.d ----
>:module tst;
>:
>:import std.stdio;
>:
>:import tmod;
>:
>:class A
>:{
>:  template Foo(T)
>:    {
>:      void Foo()
>:	{
>:	  writefln("Remove this line and everything works");
>:	}
>:    }
>:}
>:
>:void main() {}
>
> ---- tmod.d ----
>:module tmod;
>:
>:import tst;
>:
>:class B: A
>:{
>:  alias Foo!(B) foo;
>:}
>
> $ dmd -c tmod.d
> $ dmd tst.d tmod.o
> gcc tst.o tmod.o -o tst -lphobos -lpthread -lm -Xlinker
> -L/mn/tid/teori-s1/mortennk/uhh___filerogslikt/software/lib
> tmod.o(.gnu.linkonce.t_D3tst1A12Foo_C4tmod1B3FooFZv+0x16): In function
> `_D3tst1A12Foo_C4tmod1B3FooFZv':
>: undefined reference to `_arguments_Aa'
> tmod.o(.gnu.linkonce.t_D3tst1A12Foo_C4tmod1B3FooFZv+0x1c): In function `_D3tst1A12Foo_C4tmod1B3FooFZv':
>: undefined reference to `_arguments_Aa'
> collect2: ld returned 1 exit status
> --- errorlevel 1
>
> There are at least three ways to work around this: One is to remove the
> writefln() from Foo, the second is to place class B in the same file as class A,
> and the third is to compile with one command instead of two:
> $ dmd tst.d tmod.d

I can't reproduce this with dmd-0.123/dmd-0.119 and gcc 3.4.4 20050422.

What gcc version are you using?

Can you please compile and execute the code below to make sure that your libphobos is up-to-date?

- - ----
module cn.kuehne.thomas.dmd.libphobos_post122;
extern(C) cdouble* _memset128(cdouble *p, cdouble value, int count);

int main(){
	cdouble a = 0.1+0.2i;
	cdouble b;

	cdouble* c = _memset128(&b, a, 1);

	assert(a==b);
	assert(c==&b);

	return 0;
}
- - ---

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFCii/f3w+/yD4P9tIRAiZSAKDEQkqRc/gonUjHzSC5iOd3zKZHnwCcCJhS
bqKhrwfb8G6OPUfLX4E+EvI=
=pT5H
-----END PGP SIGNATURE-----
May 18, 2005
Thomas wrote:
>What gcc version are you using?

Here at my uni comp I'm using gcc-3.2.3 and dmd 0.123. At home (where I discovered the bug) I'm using gcc-4.0 and dmd.0.119.

>Can you please compile and execute the code below to make sure that your libphobos is up-to-date?

Compiles and runs fine. Besides, I always do a clean install when upgrading.

Just to be on the safe side: Are you _sure_ you compiled with
$ dmd -c tmod.d
$ dmd tst.d tmod.o

Can anyone else reproduce it?

Nick


May 18, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nick schrieb am Wed, 18 May 2005 15:24:23 +0000 (UTC):
> Thomas wrote:
>>What gcc version are you using?
>
> Here at my uni comp I'm using gcc-3.2.3 and dmd 0.123. At home (where I discovered the bug) I'm using gcc-4.0 and dmd.0.119.
>
>>Can you please compile and execute the code below to make sure that your libphobos is up-to-date?
>
> Compiles and runs fine. Besides, I always do a clean install when upgrading.
>
> Just to be on the safe side: Are you _sure_ you compiled with
> $ dmd -c tmod.d
> $ dmd tst.d tmod.o

Just tried in a clean dir again without any error message.

> Can anyone else reproduce it?
Do you use any special fags/include pathes etc. ?

Thomas

-----BEGIN PGP SIGNATURE-----

iD8DBQFCi+cC3w+/yD4P9tIRAq57AJ0aasiyiVWKI8jxsO+9KZc0BjsOqACguGs1
8ItrbDMtvnSs8gAR1ZPMC6A=
=gveI
-----END PGP SIGNATURE-----
May 19, 2005
>> Can anyone else reproduce it?
>Do you use any special f[l]ags/include pathes etc. ?

Nope, I've tried to reduce everything to a bare minimum, at it still occurs.

I've traced it further to specific differences in the object files:

-- f1.d --
import std.stdio;
import f2;
class A
{template Foo(T)
{void Foo() {writefln();}}}
void main() {}
-- end --

-- f2.d --
import f1;
class B: A
{alias Foo!(B) foo;}
-- end --

$ dmd -c f1.d
$ dmd -c f2.d
$ gcc f1.o f2.o -lphobos -lpthread -lm -L/my/lib/path

f2.o(.gnu.linkonce.t_D2f11A10Foo_C2f21B3FooFZv+0xa): In function
`_D2f11A10Foo_C2f21B3FooFZv':
: undefined reference to `_arguments_'
f2.o(.gnu.linkonce.t_D2f11A10Foo_C2f21B3FooFZv+0x10): In function
`_D2f11A10Foo_C2f21B3FooFZv':
: undefined reference to `_arguments_'
collect2: ld returned 1 exit status

$ cp f1.o f1_fail.o
$ objdump -t f1_fail.o

f1_fail.o:     file format elf32-i386

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 f1.d
00000000 l    d  .text  00000000
00000000 l    d  .data  00000000
00000000 l    d  .bss   00000000
00000000 l       .text  00000000 gcc2_compiled.
00000000 l    d  .rodata        00000000
00000000 l    d  .note  00000000
00000000 l    d  .comment       00000000
00000000 l    d  .deh_beg       00000000
00000000 l    d  .deh_eh        00000000
00000000 l    d  .deh_end       00000000
00000000 l    d  .gnu.linkonce.t_Dmain  00000000
00000000 l    d  .gnu.linkonce.t_assert_2f1     00000000
00000000 l    d  .gnu.linkonce.t_array_2f1      00000000
00000000 l    d  .ctors 00000000
00000000 g     O .rodata        00000000 _init_2f11A
00000000 g     O .data  00000000 _Class_2f11A
0000000c g     O .rodata        00000004 _vtbl_2f11A
00000000         *UND*  00000000 _main
00000000 g     O .deh_beg       00000000 _deh_beg
00000000 g     O .deh_end       00000000 _deh_end
00000000 g     F .gnu.linkonce.t_Dmain  00000005 _Dmain
00000000 g     F .gnu.linkonce.t_assert_2f1     00000017 _assert_2f1
00000000 g     F .gnu.linkonce.t_array_2f1      00000017 _array_2f1
0000003c g     O .data  00000000 _ModuleInfo_2f1
00000000         *UND*  00000000 _Dmodule_ref
00000000         *UND*  00000000 _ModuleInfo_2f2
00000000         *UND*  00000000 _ModuleInfo_3std5stdio
00000000         *UND*  00000000 _d_array_bounds
00000000         *UND*  00000000 _d_assert
00000000         *UND*  00000000 _D6object6Object8opEqualsFC6ObjectZi
00000000         *UND*  00000000 _D6object6Object5opCmpFC6ObjectZi
00000000         *UND*  00000000 _D6object6Object6toHashFZk
00000000         *UND*  00000000 _D6object6Object8toStringFZAa
00000000         *UND*  00000000 _D6object6Object5printFZv
00000000         *UND*  00000000 _Class_6Object
00000000         *UND*  00000000 _vtbl_9ClassInfo

$ objdump -t f1_fail.o > fail.txt
$ dmd f1.d f2.d
gcc f1.o f2.o -o f1 -lphobos -lpthread -lm -Xlinker -L/my/lib/path
$ objdump -t f1.o | diff fail.txt -

2c2
< f1_fail.o:     file format elf32-i386
---
> f1.o:     file format elf32-i386
16a17,18
> 0000003c l     O .data        00000004 internal
> 00000000 l    d  .gnu.linkonce.d._arguments_  00000000
26a29
> 00000000 g     O .gnu.linkonce.d._arguments_  00000008 _arguments_

In other words, the commands
$ dmd f1.d f2.d
and
$ dmd -c f1.d
produce different object files, and the latter version doesn't work (for me at
least.)

Nick