From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: Odp: Odp: Library with templates - help !!!!!!!!!!!!! Date: Sat, 20 Jan 2001 22:57:44 +0000 Organization: Customer of Energis Squared Lines: 60 Message-ID: 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> <94cjum$17k$1 AT info DOT cyf-kr DOT edu DOT pl> NNTP-Posting-Host: modem-159.helium.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news7.svr.pol.co.uk 980031473 21050 62.136.1.159 (20 Jan 2001 22:57:53 GMT) NNTP-Posting-Date: 20 Jan 2001 22:57:53 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Rafal Maj" wrote: > > > 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.) Yep, this is how it's supposed to be. > > 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. AIUI, any compiler that does this without use of the 'export' keyword does so in a non-standard way. > 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) : Correct, it's a _linking_ error, and it is correct behaviour. In fact, the linker would be wrong *not* to issue an error here. > 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. That's an unfortunate side-effect of templates. I expect the gcc developers have higher priorities at the moment than to figure out how to implement 'export', I don't know if any of the commercial compilers support this yet but I doubt it. > I read in Rhide help about CXX compile flags, that some flags (like -frepo) > are needed for such programs This isn't one such program, it's a typical use of template classes, and a common misunderstanding of how they work. > (or maybe I didn't understand docs... my english is bad). Actually, your English is very good, if you are saying it isn't your first language - I can't tell. As far as the docs go, you really need a good book to explain this (and other non-obvious features of C++). > So what compile/link flags I should use to make this library (.cc + .h) work > while using template classes in it ??? You can't fix this by using some special compiler/linker flags. There are some tricks to produce behaviour more like a non-template library. I won't attempt to explain them here, you'll get a better answer if you ask in comp.lang.c.