The following simple program doesn't link: ----- Derived.h ----- #ifndef Derived_hh #define Derived_hh
#include <istream> #include <ostream> class D : public std::iostream { public: ~D() ; } ; #endif ----- Derived.cc ----- #include "Derived.hh" D::~D() { } ----- main.cc ----- #include "Derived.hh" int main() { D d ; return 0 ; } ----- ----- The compiler command was simply "g++ main.cc Derived.cc". Output was: ----- compiler output ----- /home/kanze/tmp/ccJrgTHi.o(.gnu.linkonce.t._ZN1DC1Ev+0x29): In function `D::D()': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::basic_iostream()' /home/kanze/tmp/cctV9drU.o(.text+0x149): In function `D::~D()': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' /home/kanze/tmp/cctV9drU.o(.text+0x1fa): In function `D::~D()': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' /home/kanze/tmp/cctV9drU.o(.text+0x2ac): In function `D::~D()': : undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' /home/kanze/tmp/cctV9drU.o(.gnu.linkonce.r._ZTC1D0_Sd+0xc): undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' /home/kanze/tmp/cctV9drU.o(.gnu.linkonce.r._ZTC1D0_Sd+0x10): undefined reference to `std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()' collect2: ld returned 1 exit status ----- ----- I'm not an expert in your template instantiation strategy, but when I compile Derived.cc separately, then use nm on the object file, I find unresolved externals for symbols like std::iostream::~iostream (which shouldn't exist except as a typedef to a template instantiation, I think). From what little I understand, I would have expected a weak definition for the template instantiation (the missing function in the messages above). The relevant options I used when building the compiler were: --enable-threads --enable-__cxa_atexit --disable-nls (I don't think they have anything to do with the problem, but one never knows.) -- James Kanze -- Summary: Linker errors when deriving from std::iostream Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: critical Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: james dot kanze at free dot fr CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21056