The following case can be reproduced with the attached sample. If I have a C++ base class with a virtual function and a derived (template) class and the virtual function is implemented in a own file (-> classb.cpp), the linker does not find the symbol of the function.
If the function is implemented inline it will works. The problem seems to be that the object file (classb.o) does not contains the symbol information. The problem seems to be new with gcc 4.0. With gcc 3.3 it works. We have reproduced this with gcc 4.0.1 on Mac OS X and Linux. Using the sample: - unpack attached test.zip - call ./ma.sh in shell terminal (gcc 4.0 envirnment must be set) For me that seems to be a bug because I have not found a compiler switch, etc. to make this working. ================== -> proj.h #include <stdio.h> #include <unistd.h> class A { public: A() { ma = 0; } // A() virtual ~A() { } // A() virtual int Method1() = 0; protected: int ma; }; // A template <typename T> class B { public: B() { mb = 0; } // B() virtual ~B() { } // B() virtual int Method1(); protected: T mb; }; // B ================== -> main.cpp #include "proj.h" int main() { B<short> bs; bs.Method1(); B<int> bi; bi.Method1(); B<long> bl; bl.Method1(); return 0; } // main() ================== -> classb.cpp #include "proj.h" template class B<short>; template class B<int>; template class B<long>; template <typename T> int B<T>::Method1() { printf("pid = %ld\n", (long) getpid()); return 0; } // Method1() ================== -> ma.sh (for Mac OS X) g++ -c -O1 -arch ppc -arch i386 -o main.o main.cpp g++ -c -O1 -arch ppc -arch i386 -o classb.o classb.cpp g++ -o Test1ppc -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o classb.o -framework Carbon -lstdc++ g++ -o Test1i386 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o classb.o -framework Carbon -lstdc++ -- Summary: derived template class with virtual functions implemented in a seperated file does not link Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alexander dot schmitt at wibu dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26173