[Bf-committers] [BF-Committers] Duplicate Explicit Instantiations

Mathias Wein lynx at yafray.org
Wed Sep 12 13:03:15 CEST 2007


Kent Mein wrote:
> I believe the issue is something like this:
> in the elbeem dir we have this:
> intern/solver_interface.h:template<class Scalar> class ntlMatrix4x4;
> intern/particletracer.h:template<class Scalar> class ntlMatrix4x4;
> intern/attributes.h:template<class T> class ntlMatrix4x4;
>
> And we have the actual template in 
> intern/ntl_matrices.h
>   
Unless i'm really mistaken those three are just (template) class
declarations, they shouldn't hurt anyone. You basically do that to
avoid including headers in headers in headers...it's enough to
declare a type when you only store/pass pointers/references
of that type.

An explicit template instantiation would for example be:
template class ntlMatrix4x4<gfxReal>;
This makes the compiler generate all code for this template even
when it is never used in code.

The information that GCC doesn't do automatic instantiation is plain
wrong i think. When i was new to C++ i didn't even know you can do
explicit instantiation :D
Not very common these days i think, except for library purposes.

What seems to be the problem here is that the linker on Irix can't
handle duplicate instantiations (in contrast to the GNU linker), and hence
MIPSpro seems to have a special prelinker that collects all templates that
still need to be instantiated and only creates them once
(well, that probably saves compile time too...GCC's template performance
is sometimes quite lacking, to say it politely).

No idea which template the prelinker is moaning about, or what settings
you use.

Some possibly interesting links:
http://www.network-theory.co.uk/docs/gccintro/gccintro_60.html
http://www.risc.uni-linz.ac.at/education/courses/ws2003/intropar/origin-new/CC_PG/sgi_html/ch04.html


Mathias



More information about the Bf-committers mailing list