automatic template instanciation (g++, -frepo)

U

Uwe Mayer

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
 
B

BobR

Uwe Mayer said:
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?
 
J

James Kanze

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. That
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top