A file can be included as follows:
File, a string, is to point out a file. The contents of this file are included as is, at the position of the directive.
Include files are typically used for record and macro definitions that are shared by several modules. It is recommended to use the file name extension .hrl for include files.
File can start with a path component $VAR, for some string VAR. If that is the case, the value of the environment variable VAR as returned by os:getenv(VAR) is substituted for $VAR. If os:getenv(VAR) returns false, $VAR is left as is.
If the filename File is absolute (possibly after variable substitution), the include file with that name is included. Otherwise, the specified file is searched forin the following directories, and in this order:
- The current working directory
- The directory where the module is being compiled
- The directories given by the include optionFor details, see the erlc(1) manual page in ERTS and compile(3) manual page in Compiler.
include_lib is similar to include, but is not to point out an absolute file. Instead, the first path component (possibly after variable substitution) is assumed to be the name of an application.
The code server uses code:lib_dir(kernel) to find the directory of the current (latest) version of Kernel, and then the subdirectory include is searched for the file file.hrl.