This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

templates undefined refrence problem

I can't seem to be able to instantiate template classes of different
types.  I am using a template class that contains another template class
with seperate definitions and declarations in headers and implementation
files for each class.  When I compile, I consistantly get compiler
errors "undefined refrence" even though they compile to .o files
successfully.  The problem comes when it tries to link.

It appears to me that the compiler is not automaticly producing the
specializations that I am instantiating in my main function.  I have
tried differennt method to try and make this happen, by using -frepo,
bare compiler options, compiling all files at once but to no avail.
I was unable to find any compiler options to turn on template based on
the instantitation.  Using GCC 3.0.3 and 2.95.3.

What am I doing wrong?

#ifndef T_HH
#define T_HH
template <class T> class A
#include "A.hh"
template <class T> A<T>::A()
{  //...

#include "A.hh"
#ifndef B_HH
#define B_HH
template <class T> class B
        A<T> a;
#include "B.hh"
template <class T> B<T>::B()
{ //...
#include "B.hh"
int main()
    A<int> ai;
    A<double> ad;
    return 0;

CXX = g++
CXXFLAGS = -g -Wall -frepo
objects = A.o B.o main.o
all: $(objects)
 $(CXX) $(CXXFLAGS) -o $(program) $(objects)
A.o: A.hh
B.o: B.hh A.hh
main.o: B.hh

$ make
g++ -g -Wall -frepo   -c -o A.o
g++ -g -Wall -frepo   -c -o B.o
g++ -g -Wall -frepo   -c -o main.o In function `int main()': warning: unused variable `A<int> ai' warning: unused variable `A<double> ad'
g++ -g -Wall -frepo -o  A.o B.o main.o
main.o: In function `main': undefined reference to `A<int>::A()' undefined reference to `A<double>::A()'
collect2: ld returned 1 exit status
make: *** [all] Error 1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]