automatic template instanciation (g++, -frepo)



 DEVELOP > c-Plus-Plus > automatic template instanciation (g++, -frepo)

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Uwe Mayer"
Date: 02 Aug 2007 08:15:22 AM
Object: automatic template instanciation (g++, -frepo)
Hi,
I am writing a library, which contains classes with template
memberfunctions. If I do not instanciate the templates I want to use, I get
an "undefined reference" link-error.
The FAQ
(http://www.new-brunswick.net/workshop/c++/faq/templates.html#faq-35.15)
explained I had to explicitly name the instanciations I wanted to use. That
works, but is awfully tedious.
The gcc manual
(http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Template-Instantiation.html#Template-Instantiation)
suggests the use of the -frepo flag.
1. Did I understand it correctly, that this is supposed to handle the
automatic template instanciation, at the cost of longer compile /link time?
2. This also doesn't work. "collect2" is called, and the .rpo files are
generated, but now I even get a link error on something that looks like its
comming from STL:
[...]
collect: recompiling test6.cpp
collect: relinking
collect: recompiling test6.cpp
collect: relinking
test6-test6.o: In function `main':
test6.cpp:48: undefined reference to `ml::LinePlot&
ml::Axes::plot3<gsl_vector>(gsl_vector*, gsl_vector*, gsl_vector*, char*)'
libmatplot.so: undefined reference to `std::_Rb_tree<double,
std::pair<double const, ml::Axes*>, std::_Select1st<std::pair<double const,
ml::Axes*> >, std::less<double>, std::allocator<std::pair<double const,
ml::Axes*> > >::_M_erase(std::_Rb_tree_node<std::pair<double const,
ml::Axes*> >*)'
Any ideas?
Thanks in advance
Ciao
Uwe
.

User: "James Kanze"

Title: Re: automatic template instanciation (g++, -frepo) 03 Aug 2007 04:08:41 AM
On Aug 2, 3:15 pm, Uwe Mayer <merk...@hadiko.de> wrote:

I am writing a library, which contains classes with template
memberfunctions. If I do not instanciate the templates I want
to use, I get an "undefined reference" link-error.

That's curious. I never do.

The FAQ
(http://www.new-brunswick.net/workshop/c++/faq/templates.html#faq-35.15)
explained I had to explicitly name the instanciations I wanted to use. Th=

at

works, but is awfully tedious.

I'm not too sure I understand what the FAQ is getting at here.
It puts the implementation of the function templates in a source
file; normally, you put them in the header, unless the template
is exported (and all of your target compilers support export).

The gcc manual
(http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Template-Instantiation.ht...)
suggests the use of the -frepo flag.

Is this still supported? I thought that such options where just
there to handle compatibility issues with older compilers, like
CFront. At any rate, I never use them, and I've never had the
slightest problem.
For compilers which do use a repository, like Sun CC, you'll
probably need a special tool to build the library: for Sun CC,
for example, "CC -xar", rather than simply "ar". That tool will
normally be furnished with the compiler, however. And such is
not the case with g++; no special tool is needed, since g++
doesn't normally use a repository.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.

User: "BobR"

Title: Re: automatic template instanciation (g++, -frepo) 02 Aug 2007 01:11:11 PM
Uwe Mayer <merkosh@hadiko.de> wrote in message...

Hi,
I am writing a library, which contains classes with template
memberfunctions. If I do not instanciate the templates I want to use, I

get

an "undefined reference" link-error.

The gcc manual

(http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Template-Instantiation.html#Tem
plate-Instantiation)

suggests the use of the -frepo flag.

1. Did I understand it correctly, that this is supposed to handle the
automatic template instanciation, at the cost of longer compile /link

time?
Did you read the "Where's the Template?" section in the GCC docs?
--
Bob R
POVrookie
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER