Date: Tue, 14 Feb 1995 07:33:36 +0100 (CET) From: "Roland Exler" Sender: k3a0270 AT pop DOT uni-linz DOT ac DOT at Reply-To: R DOT Exler AT jk DOT uni-linz DOT ac DOT at To: Subject: Templates with gcc 2.6.3 Thanks to Jan Reimers and especially to Gordon Hogenson for there replies on my template-problem. I'm just wondering that there are only two people out there knowing about this problem. Are the others not using templates or just very easy constructions? After reading the suggestions mentioned and chapter 7.4, and 7.5 ('C++-Extensions/Declarations and Definitions in One Header and Where's the Template) of the gcc-manual i tried some ways with programs already compiled and linked ok with gcc 2.6.0. At now, I think the following way is the best, but there are also problems going this way: 1) I put the template-declarations in the header-files and the template-definitions of the member-function in a seperate .cc file. 2) Compiling the modules of the project I include only the headers, so no templates will be instantiated. 3) For each instantiation of an template-class I write a short file, eg.: #include "xxx.h" #include "xxx.cc" template class xxx; template ostram& operator<<(ostream& os, xxx& data); This files are compiled and an template-library 'libtemp.a' was built of them, which is to be updated as needed. 4) linking the programs I specify -ltemp. Seperation of the headers and the implementation speeds up the compiler and linking the library is very efficient. The major problem going this way is to know which instantiations are used in the program. This is no problem with non-virtual functions since the linker will give an meaningful error 'undefined reference to ...', but with virtual functions you may get 'undefined reference to __pure_virtual' where it's not so easy to find the instantiation missing in the library. There may be other problems which I've not encountered jet, but I wanted to inform you now. Roland +---------------------------------------+---------------------------+ I Roland Exler I EMAIL: I I Universitaet Linz I R DOT Exler AT jk DOT uni-linz DOT ac DOT at I I Institut fuer Elektrische Messtechnik I I I Altenbergerstr. 69 I Phone: I I A-4040 Linz, AUSTRIA I + 43 732 2468 9205 I +---------------------------------------+---------------------------+