From: pavenis AT lanet DOT lv To: "Rafal Maj" , djgpp AT delorie DOT com Date: Sat, 20 Jan 2001 20:23:21 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Library with templates - help !!!!!!!!!!!!! Message-ID: <3A69F3B9.12173.67F409@localhost> In-reply-to: <94c3au$791$1@info.cyf-kr.edu.pl> X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 20 Jan 2001, at 14:21, Rafal Maj wrote: > Hi, > I have problem when I compile program using library with templates. > Project file contains bugmain.cc & bug.cc. In this example, bugmain.cc is my > mian program, bug.cc is my library & bug.h is library header. I have > problems to build my program when I'm using templates in my library. > I get error report : > > Compiling: bugmain.cc > no errors > Creating: bug.exe > Error: bugmain.o: In function `main': > bugmain.cc(2) Error: undefined reference to `box::move(int)' > There were some errors > > Box is my template class and move is simple function inside bug ctemplate > class. > Can somebody help me ??????? > > I know, that there are options like -frepo, no-implict-templates, etc... but > I realy don't know how to set them to make my exaple work. > > If You can help me, please write exacly what should be compiler & linker > options, and what I have to change inside my source files. > Maybe You can correct my project file, then send it to me > maj_rafal AT poczta DOT onet DOT pl )? > > ============ PROJECT WINDOW ========== > bug.cc > bugmain.cc > ================== BUG.CC ================ > template void box::move(typ d) { > x+=d; y+=d; > } Compiler should see this code (bug.cc) when compiling bugmain.cc. C++ standard includes keyword 'export' (not implemented in GCC yet, don't ask me when this will happen ...) for separate compilation of templates. So append contents of bug.cc to bug.h and all should be OK > ================== BUGMAIN.CC ================= > #include "bug.h" > main() { > box b; > b.move(5); > } > ================== BUG.H =============== > template > class box { > public : > typ x,y; > void move(typ d); > }; > ========================================================= > > Thanks in advice ;-) > Rafa >