Thread overview
DMD 0.130: Template modules cannot use a different -release setting than a module which uses it
Sep 07, 2005
Burton Radons
Sep 10, 2005
Thomas Kühne
Sep 10, 2005
Sean Kelly
September 07, 2005
I don't think this long-standing bug has been codified in a formal bug post, so here's one.

This is the content of f.d:

        import g;

        void main ()
        {
                T! () ();
        }

This is the content of g.d:

        template T ()
        {
                void T ()
                {
                        assert (0);
                }
        }

Here is a compilation script for these modules:

        dmd f.d -c
        dmd g.d f.obj -release

The linking stage fails with the error message on Linux:

        f.o(.gnu.linkonce.t_D1g9Template_8TemplateFZv+0x9): In function
`_D1g9Template_8TemplateFZv':
: undefined reference to `_assert_1g'

It should compile properly.  The cause is that f.d and g.d are compiled with different values for "-release".  DMD should produce module assertion functions regardless of the setting of "-release".
September 10, 2005
Burton Radons schrieb:

> I don't think this long-standing bug has been codified in a formal bug post, so here's one.
> 
> This is the content of f.d:
> 
>         import g;
> 
>         void main ()
>         {
>                 T! () ();
>         }
> 
> This is the content of g.d:
> 
>         template T ()
>         {
>                 void T ()
>                 {
>                         assert (0);
>                 }
>         }
> 
> Here is a compilation script for these modules:
> 
>         dmd f.d -c
>         dmd g.d f.obj -release
> 
> The linking stage fails with the error message on Linux:
> 
>         f.o(.gnu.linkonce.t_D1g9Template_8TemplateFZv+0x9): In function
> `_D1g9Template_8TemplateFZv':
> : undefined reference to `_assert_1g'
> 
> It should compile properly.  The cause is that f.d and g.d are compiled with different values for "-release".  DMD should produce module assertion functions regardless of the setting of "-release".

Baiscally the same as the following complex test case: http://dstress.kuehne.cn/www/dstress.html#typeinfo_init_02

Thomas

September 10, 2005
In article <dfnpcd$16ad$1@digitaldaemon.com>, Burton Radons says...
>
>I don't think this long-standing bug has been codified in a formal bug post, so here's one.
>
>This is the content of f.d:
>
>        import g;
>
>        void main ()
>        {
>                T! () ();
>        }
>
>This is the content of g.d:
>
>        template T ()
>        {
>                void T ()
>                {
>                        assert (0);
>                }
>        }
>
>Here is a compilation script for these modules:
>
>        dmd f.d -c
>        dmd g.d f.obj -release
>
>The linking stage fails with the error message on Linux:
>
>        f.o(.gnu.linkonce.t_D1g9Template_8TemplateFZv+0x9): In function
>`_D1g9Template_8TemplateFZv':
>: undefined reference to `_assert_1g'

I complained about this on the general forum recently.  If the template module contains only template code, an easy fix is to always compile that module without -release specified.  The object file will only contain the generated assert functions, and the template code generated by other builds will call or not call them as appropriate.  This is what I've done for Ares.  The real solution is probably to build debug and release versions of your libraries and direct users to link to the appropriate one, but that isn't feasible for me until DMD supports this for Phobos.  Either way, it's a tad weird that all-template modules need to be compiled at all.  Though that may simply be something I've gotten used to from C++.


Sean