|
|
A ``library'' is an archive of object files. There are several issues with libraries when using templates. First of all, as noted in ``Performance'' , it is possible to pre-instantiate needed template functions into an archive and then specify that archive on the link line and do away with the need for any instantiation at all.
When instantiating templates that will be used internally within an archive, use the CC -Tprelink_objects option. Use of this option will cause the prelinking phase to run, but the linking phase to be suppressed. A typical usage might be:
CC -c a.C b.C c.C CC -Tprelink_objects ar rv libfoo.a a.o b.o c.oor
CC -Tprelink_objects a.C b.C v.C ar rv libfoo.a a.o b.o c.o
Another issue with libraries is the notion of ``closure''. Suppose that you provide a library to another development group, and that the library uses templates internally (whether or not the applications that use the library do is irrelevant). Instantiation in such a case will fail, because there are no library sources to replay. Therefore a library must be self-contained as regards template functions; if an object file in the library uses templates, some other object file in that library should contain definitions of the necessary template functions.