This is the mail archive of the gcc@gcc.gnu.org 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]

Templated derived classes



Given the following code:

// bug.cpp
//
struct Base 
{
         virtual ~Base() {};
};

template<class T>
struct Derived : public Base
{
         virtual ~Derived() {};
};


int main()
{
        Derived<int> tmp;
        //Derived tmp;
}

Under AIX with snapshot egcs-20000703, when I try to compile and link
with "g++ -o bug bug.cpp" I get a "Undefined symbol: Derived<int>
virtual table".  If I make Derived a non template class, it compiles
and links without a problem.  It links fine using gnu ld under x86
linux, its just AIX's ld that I seem to have a problem with.  I read
in the faq that templates get instantiated in the file containing the
first non-inline virtual method.  I doubt that it applies here as
there is only one file, but tried adding non-inline virtual methods in
Both Base and Derived just to see if it would make a difference, but
it didn't help.  Looking at a nm output of bug.o shows that the vtable
of Derived is both defined and undefined...?  If anyone has any idea
what the problem is or how I could get this code to link under AIX,
I'd appreciate hearing about it.  Thanks,

Matt


Matt

"nm bug.o" after "g++ -c bug.cpp":

._._4Base            t        256
._._t7Derived1Zi     t        100
.__4Base             t        512
.__builtin_delete    U          -
.__rtti_si           U          -
.__rtti_user         U          -
.__t7Derived1Zi      t        392
.__tf4Base           t        588
.__tft7Derived1Zi    t        708
.main                T          0
LC..5                d       1196       4
LC..8                d       1204       4
TOC                  d       1184
_._4Base             d        896      12
_._t7Derived1Zi      d        884      12
_GLOBAL_.F.main      D       1008
__4Base              d        968      12
__divss              U          -
__divus              U          -
__mulh               U          -
__mull               U          -
__quoss              U          -
__quous              U          -
__t7Derived1Zi       d        908      12
__tf4Base            d        980      12
__tft7Derived1Zi     d        992      12
__ti4Base            B       1208       8
__ti4Base            d       1192       4
__tit7Derived1Zi     B       1216      12
__tit7Derived1Zi     d       1200       4
_aixbug.rw_cpp       d        920      48
_aixbug.rw_cpp       t        848      21
_vt.4Base            d       1184       4
_vt.t7Derived1Zi     U          -
_vt.t7Derived1Zi     d       1188       4
aix-bug.cpp          f          -
main                 D        872
main                 d        872      12


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