From: bryan AT alpha DOT hcst DOT com (Bryan Murphy) Newsgroups: comp.os.msdos.djgpp Subject: Problem Compiling with C++ (more detailed) Date: 25 Feb 1997 13:48:45 -0500 Organization: Hassler Communication Systems Technology, Inc. Lines: 68 Message-ID: <5evc6d$ed4@alpha.hcst.com> NNTP-Posting-Host: alpha.hcst.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Ok, here is an example of the problem I am having compiling and linking my code. I'm starting to think it has something to do with the templates, but I'm unsure why, as I could only reproduce this error when using them. /***** FILE: classlib.h ************************************************/ #ifndef _CLASSLIB #define _CLASSLIB #include "iostream.h" template class TESTCLASS { public: TESTCLASS(char *newname); void PrintName(); void InlinePrint() { cout << "Inline: " << name << endl; }; void StoreData(TYPE newdata) { data = newdata; } private: char *name; TYPE data; }; #endif /***** FILE: classlib.cc ***********************************************/ #include "classlib.h" #include "string.h" template TESTCLASS::TESTCLASS(char *newname) { name = new char[strlen(newname)]; strcpy(name,newname); }; template void TESTCLASS::PrintName() { cout << name << endl; }; /***** FILE: test.cc **************************************************/ #include "classlib.h" void main() { cout << "This should compile correctly, link and run." << endl; TESTCLASS Test("This is my Name"); Test.PrintName(); Test.InlinePrint(); Test.StoreData(10); }; /***** Compilation Output ***********************************************/ gcc test.cc classlib.cc -lgpp c:/djgpp/tmp\ccdaaaaa(.text+0x7a):test.cc: undefined reference to `TESTCLASS::TESTCLASS(char *)' c:/djgpp/tmp\ccdaaaaa(.text+0x86):test.cc: undefined reference to `TESTCLASS::PrintName(void)'