From: "Rafal Maj" Newsgroups: comp.os.msdos.djgpp Subject: Odp: Odp: Library with templates - help !!!!!!!!!!!!! Date: Sat, 20 Jan 2001 19:03:55 +0100 Organization: Academic Computer Center CYFRONET AGH Lines: 82 Message-ID: <94cjum$17k$1@info.cyf-kr.edu.pl> References: <94c3au$791$1 AT info DOT cyf-kr DOT edu DOT pl> <94cba9$5a0$1 AT info DOT cyf-kr DOT edu DOT pl> NNTP-Posting-Host: d-94-53-28.cyfronet.krakow.pl Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Trace: info.cyf-kr.edu.pl 980013846 1268 149.156.1.188 (20 Jan 2001 18:04:06 GMT) X-Complaints-To: news AT cyf-kr DOT edu DOT pl NNTP-Posting-Date: 20 Jan 2001 18:04:06 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Sorry, maybe I don't understand way of writing C++ libraries... but I think this is correct : In file lib.h I write : class cBox { public : void move(); } In lib.cc : void cBox::move() { /* ..............very long algoritm............ / } In main.cc : #include "lib.h" main() { cBox obj; obj.move(); } In project file : - add "main.c" - add "lib.cc" Now everything is correct, when I'm doing change in main.cc only main.cc is re-compiling, same fore lib.cc But when I add template to cBox : lib.h : template class cBox { public : void move(); } lib.cc : template void cBox::move() { /* ..............very long algoritm............ */ } main.c : #include "lib.h" main() { cBox obj; obj.move(); } I get error while building (not when compiling) : Compiling: main.cc no errors Creating: main.exe Error: main.o: In function `main': main.cc(2) Error: undefined reference to `box::move()' There were some errors When I copy-paste source of lib.cc / lib.h into main.cc everything is O.K., but any small change to main() function makes class cBox recompile and vice-versa. In my program, when it is divided to several files it compile + build after changing one library in about 5sec, when this program was in one file it took about 20s to re-compile after every change. I read in Rhide help about CXX compile flags, that some flags (like -frepo) are needed for such programs (or maybe I didn't understand docs... my english is bad). When I simply select compile option -frepo it didn't help. So what compile/link flags I should use to make this library (.cc + .h) work while using template classes in it ??? Please help... Użytkownik Ian Miller w wiadomooci do grup dyskusyjnych napisał:t6jf5hsbjr8k83 AT corp DOT supernews DOT co DOT uk... > "Rafal Maj" writes: > > > Yes, > > but when definiton (in real program - very long) of my class is in box.h, > > then it is re-compiled every time, with can take very much time. > > What Jason Green showed you is the normal way of writing template > classes and their functions... > > > I want to > > have definition in other .cc file to re-compile it only when necessary, in > > bug.h I want only definition of my class. > > ...and this isn't. (I believe you mean "declaration" by the way.) > > > When I write definition of normal class in my library *.cc file - OK > > When I write definition of template class in my main *.cc file - OK > > When I write definition of template class in my library *.cc file - error ! > > That's just the way template classes work, I'm afraid. > (So far as I know anyway.) > > Some compilers can "compile the headers" on order to answer > your objection to writing the code correctly, but I don't > think gcc does so yet. > > Regards, > Ian