473,413 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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/worksho...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....-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
Aug 2 '07 #1
2 3299

Uwe Mayer <me*****@hadiko.dewrote 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....ation.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
Aug 2 '07 #2
On Aug 2, 3:15 pm, Uwe Mayer <merk...@hadiko.dewrote:
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/worksho...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....stantiation.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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 3 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Victor Almeida | last post by:
Hi, I hate putting #include "mytemplate.cc" in the end of header files. I saw in the gcc documentation that they have a -frepo option to do automatic instatiation of my template code. I put it and...
1
by: K.S. | last post by:
If have template lets call it template class MyTemplate<class T> and the files MyTemplate.cc & MyTemplate.hh In /* MyTemplate.cc */ // definitions .... template class MyTemplate<someType>;...
2
by: ik | last post by:
Hello All, I am facing problem with classes having some functions as templates. Is it a limitation of C++ templates not to have class functions as templates ? I am attaching the code below, I am...
8
by: | last post by:
This code get's a link error (I'm guessing because the template isn't being instantiated)... // For using templates to simplify deleting items template <class T> // Returns the next ADHL in the...
7
by: yilled_fred | last post by:
Hi can anyone tell me why the following code cannot/doesn't compile? I get the following error while compiling (g++ -c ): "In member function `void derivedclass<S>::foo()': test.h:20 error:...
2
by: gregory_may | last post by:
Anyone know how to add the subroutine/function name into a try catch block? Ideally, it would be great to have this as part of the automatic template that gets created. Try Catch ex As...
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
16
by: Hendrik Schober | last post by:
Hi, suppose we have template< typename T > struct X; and some specializations: template<>
1
by: toto | last post by:
Dear friends, I'm quite new in template programming but they are giving me a very hard time. I'm using gcc as a compiler and I'm mainly develop for linux and windows. My problem is that I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.