home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!apollo.hp.com!netnews
- From: vinoski@apollo.hp.com (Stephen Vinoski)
- Subject: Re: Was: Template Use <sigh>
- Sender: usenet@apollo.hp.com (Usenet News)
- Message-ID: <C1A4n9.1Iz@apollo.hp.com>
- Date: Fri, 22 Jan 1993 23:45:09 GMT
- References: <1jp50dINNk34@rs6000.bham.ac.uk> <81348@hydra.gatech.EDU>
- Nntp-Posting-Host: srv.ch.apollo.hp.com
- Organization: Hewlett-Packard Corporation, Chelmsford, MA
- Lines: 66
-
- In article <81348@hydra.gatech.EDU> mhopper@cerl.gatech.edu (Michael A. Hopper) writes:
- >In article <1jp50dINNk34@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
- >->Anyway, my problem in more detail is this: I have three directories
- >->which contain the following:
- >->
- >-> 1/ The .C and .H files defining the template class LookupTable.
- >-> 2/ The .C and .H files of an algorithm which uses LookupTable<unsigned
- >-> char>
- >-> 3/ A main.C which binds the whole lot together, but does not itself
- >-> use LookupTable<unsigned char>
- >->
- >->The problem is that at link time, no template instantiation takes
- >->place and then the real linker complains about all my member functions
- >->of LookupTable<unsigned char> being unresolved.
- >->
- >->There are unresolved symbols, yet the instantiator doesn't do anything
- >->about them.
- >->
- >->What am I doing wrong??? Any ideas?
- >->
- >->Guy.
- >
- >Put ALL of your template code in header (.h) files. Do not put template
- >code (member functions) in .c files. In other words, get rid of loopuptable.c
- >(or whatever you called it).
- >
- >This worked for me.
-
- It may work, but it is unnecessary with cfront 3.0.X. We have several
- very large systems under development here that utilize templates with
- separate header and implementation files.
-
- The cfront auto instantiation system won't bother attempting template
- instantiation if it cannot find its type map, which is the file
- ptrepository/defmap by default. If one builds a library archive
- containing unresolved template references in directory "A", then one
- attempts to link against that archive in directory "B", template
- instantiation will fail unless directory "B" happens to contain a type
- map that allows cfront to locate all the types necessary to perform
- the instantiation. If the user in directory "B" has the necessary
- write permissions for the repository in directory "A", s/he can use
- the -ptr option to the compiler to specify that repository instead of
- the default, and the link should then work. If repository "A" is not
- writable, the user can specify a writable directory as the first
- repository on the command line, followed by another -ptr specifying
- "A" as a read-only repository:
-
- CC ... -ptr my_ptrep -ptr A/ptrepository ...
-
- All of this is well documented by the cfront release notes.
-
- We have found it useful to create archive libraries that utilize
- templates in three steps:
-
- 1) create the archive library
- 2) compile a dummy main program and link it against the archive
- 3) redo the archive to include all of its original object files plus
- the object files created by the template instantiation system
-
- This approach prevents archive library clients from having to perform
- template instantiation for that archive. A similar approach is
- mentioned in the cfront 3.0 release notes, I think. Makes sense and
- saves a lot of needless instantiation time.
-
- -steve
-
-