g++ deriving from a template class link error
Lawrence W. Leung
larryl@pasteur.EECS.Berkeley.EDU
Sun Dec 31 19:09:00 GMT 2000
hi,
I ran into this strange link error when attempting to compile a program
with a simple class derived from a template class. I have duplicated the
simple test program in two ways: 1. with everything in different files
2. with everything in one file. #1 compiles, links and runs. #2 compiles
but doesn't link.
Axes is the templated class and deriv is the derived class.
#2 returns this error:
[ricki@ll233 test]$ g++ -o out deriv.cpp axes.cpp
/tmp/cc82pCjC.o: In function `main':
/tmp/cc82pCjC.o(.text+0x10): undefined reference to `Axes<int>::Axes(int)'
/tmp/cc82pCjC.o(.text+0x7a): undefined reference to
`Axes<int>::~Axes(void)'
/tmp/cc82pCjC.o(.text+0xaa): undefined reference to
`Axes<int>::~Axes(void)'
/tmp/cc82pCjC.o: In function `deriv::deriv(void)':
/tmp/cc82pCjC.o(.deriv::gnu.linkonce.t.(void)+0x11): undefined reference
to `Axes<int>::Axes(int)'
/tmp/cc82pCjC.o(.deriv::gnu.linkonce.t.(void)+0x37): undefined reference
to `Axes<int>::~Axes(void)'
/tmp/cc82pCjC.o: In function `deriv::~deriv(void)':
/tmp/cc82pCjC.o(.gnu.linkonce.t._._5deriv+0x14): undefined reference to
`Axes<int>::~Axes(void)'
collect2: ld returned 1 exit status
In #1 all the stuff from #2 is condensed into a "test.cpp" file and
compiled with "g++ test.cpp".
I've included all the files I've used. I'm using the compiler that came
with Mandrake 7.2 (g++ 2.95.3).
Any ideas?
Thanks
-Larry
More information about the Gcc-help
mailing list