Message-ID: <38C03E09.E7E7A8AC@bluemartini.com> From: Sergei Severin X-Mailer: Mozilla 4.7 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: building source with C++ templates Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 61 Date: Fri, 03 Mar 2000 22:35:02 GMT NNTP-Posting-Host: 209.157.149.218 X-Complaints-To: abuse AT flash DOT net X-Trace: news.flash.net 952122902 209.157.149.218 (Fri, 03 Mar 2000 16:35:02 CST) NNTP-Posting-Date: Fri, 03 Mar 2000 16:35:02 CST Organization: FlashNet Communications, http://www.flash.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I am trying to figure out how to compile and link my program if I am using C++ templates. Here is the simple example of what I am trying to accomplish: - I have 3 files - File 1 : test.h #iclude template class foo { public: foo(T t); T getValue(); private: T val; }; - File 2 : test.cpp #include "test.h" template foo::foo(T t) { val = t; } template T foo::getValue() { return val; } - File 3: main.cpp #include "test.h" void main () { foo* f = new foo(5); cout << f->getValue(); } - When I try to build it like: gxx -o test.exe *.cpp I get d:/djgpp/tmp\ccTABxia.o(.text+0x23):main.cpp: undefined reference to `foo::foo(int)' d:/apps/djgpp/tmp\ccTABxia.o(.text+0x5f):main.cpp: undefined reference to `foo::getValue(void)' collect2: ld returned 1 exit status I manage to build everything fine only in two cases: 1. if don't use templates at all or 2. If I use templates but keep declarations and implementations in one .h file In my project, the files are pretty large and I am required to separate class declarations from the implementation of member functions. So if anyone knows how to fix my problem, I would really appreciate your help with this. Thank you, Sergei Severin