The implicit inclusion of source files is a method of finding definitions of template entities. This method is enabled for the compiler by default (see also the -K implicit_include
option on "Template options") and can be disabled with -K no_implicit_include
. Please refer to the notes on "Basic aspects" with regard to disabling implicit inclusion.
If implicit inclusion is enabled, the compiler looks for the definition of a template entity in accordance with the following principle: if a template entity is declared in a header file named basename .h
and no definition for it is available in the compiled source code, the compiler will assume that the definition for that template entity is in a source file with the same base name as the header file and with a suitable suffix (e.g. basename .C
).
Let us assume, for example, that a template entity ABC::f
is declared in the header file xyz.h
. If the instantiation of ABC::f
is requested on compilation, but no definition of ABC::f
exists in the compiled source code, the compiler will search the directory containing the header file for a source file with the base name xyz
and a suitable suffix (e.g. xyz.C
). If such a file exists, it will be treated as if it were included at the end of the source file.
The following suffixes are checked in this order: c, C, cpp, CPP, cxx, CXX, cc, CC, c++ und C++. These are the suffixes that are interpreted as C ++ source by default. The -Y F
option has no effect on the suffixes checked for implicit inclusion.
To ensure that the file containing the definition of a particular template entity can be found during instantiation, the complete path name of the file with the declaration of the template must be known. This information is not available in files containing #line
directives. Consequently, implicit inclusion is not possible in such cases.
Implicit inclusion and the make
utility
When working with the make
utility, implicit inclusions must be taken into account when generating file dependency lines. In other words, the object file depends on explicitly included headers as well as implicitly included files with template definitions.
When using the -M
option, implicit inclusions will be taken into account in automatic instantiation mode only if the instantiation information files have been correctly built.
The following steps are required for this purpose:
Compile all source files.
Link the program together so that all instantiations are assigned.
Generate file dependency lines with the
make
program using the-M
option (see also "Options for selecting compilation phase").Repeat steps 2 and 3 if the generated template instances have changed.