This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: c++ template instanciation and dlls on win32
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: 'Mathieu Lacage' <Mathieu dot Lacage at sophia dot inria dot fr>
- Cc: GCC-help at gcc dot gnu dot org
- Date: Mon, 02 Jul 2007 09:21:35 +1200
- Subject: RE: c++ template instanciation and dlls on win32
> From: Mathieu Lacage
> Sent: Monday, 2 July 2007 1:40 a.m.
>
>
> On Sun, 2007-07-01 at 22:30 +1200, Danny Smith wrote:
>
> > > Here is my sample code:
> > > http://www-sop.inria.fr/dream/personnel/Mathieu.Lacage/tmp.tar.gz
> >
> >
> > This is what I would do:
> >
> > Exolicitly, force instantiation of your template instance in dll:
>
> ok.
>
> >
> > diff -c3p tmp/test.cc tmp0/test.cc
> > *** tmp/test.cc Sat Jun 30 21:30:22 2007
> > --- tmp0/test.cc Sun Jul 1 15:49:20 2007
> > ***************
> > *** 1,5 ****
> > --- 1,8 ----
> > #include "test.h"
> >
> > + // instantiate
> > + template class Test <0>;
> > +
> > void Function (void)
> > {
> > Test<0>::Exec ();
> >
> >
> >
> > Explictly mark the reference to your imported instantation
> as imported.
>
> This begs the question as to whether it is possible to automate the
> import: can I tell gcc that it should not implicitely generate any
> template instanciation and that it should import it instead ? I cannot
> see myself having to explicitely import every possible instanciated
> template so, I am trying to find a workaround.
>
Windows targets uses "linkonce" sections to implement vague linkage.
And the function Test<0>::Exec () is indeed put into a linkonce section
in both main.o and test.o.
When we build an exe from those two objects, only one copy of the
function is retained, and everything works.
However, when the linker builds a dll from test.o, the dll and the
import library used to link to the dll do not retain the .linkonce
section characteristics. Hence we get two copies of Test<0>::Exec ().
Perhaps you should follow up on binutils list.
Danny