Unlike -qtempinc, the -qtemplateregistry compiler option does not impose
specific requirements on the organization of your source code. Any
program that compiles successfully with -qnotempinc will compile
with -qtemplateregistry.
The template registry uses a "first-come first-served" algorithm:
- When a program references a new instantiation for the first time, it is
instantiated in the compilation unit in which it occurs.
- When another compilation unit references the same instantiation, it is not
instantiated. Thus, only one copy is generated for the entire
program.
The instantiation information is stored in a template registry file.
You must use the same template registry file for the entire program.
Two programs cannot share a template registry file.
The default file name for the template registry file is
templateregistry, but you can specify any other valid file name to
override this default. When cleaning your program build environment
before starting a fresh or scratch build, you must delete the registry file
along with the old object files.
If two compilation units, A and B, reference the same instantiation, the
-qtemplateregistry compiler option has the following effect:
- If you compile A first, the object file for A contains the code for the
instantiation.
- When you later compile B, the object file for B does not contain the code
for the instantiation because object A already does.
- If you later change A so that it no longer references this instantiation,
the reference in object B would produce an unresolved symbol error.
When you recompile A, the compiler detects this problem and handles it as
follows:
- If the -qtemplaterecompile compiler option
is in effect, the compiler automatically recompiles B during the link step,
using the same compiler options that were specified for A. (Note, however, that if you use separate compilation and linkage
steps, you need to include the compilation options in the link step to ensure
the correct compilation of B.)
- If the -qnotemplaterecompile compiler option is in effect, the
compiler issues a warning and you must manually recompile B.
Because the -qtemplateregistry compiler option does not impose
any restrictions on the file structure of your application, it has less
administrative overhead than -qtempinc. You can make the
switch as follows:
- If your application compiles successfully with both -qtempinc
and -qnotempinc, you do not need to make any changes.
- If your application compiles successfully with -qtempinc but
not with -qnotempinc, you must change it so that it will compile
successfully with -qnotempinc. In each template definition
file, conditionally include the corresponding template implementation file if
the __TEMPINC__ macro is not defined. This is illustrated in
Example of -qtempinc.
