This option causes the compiler to treat filename as if it appears in the first line of a primary source file as a #include preprocessor directive. Consider the source file t.c:
main()
{
...
}
|
If you compile t.c with the command cc -include t.h t.c, the compilation proceeds as if the source file contains the following:
#include "t.h"
main()
{
...
}
|
The first directory the compiler searches for filename is the current working directory and not the directory containing the main source file, as is the case when a file is explicitly included. For example, the following directory structure contains two header files with the same name, but at different locations:
foo/
t.c
t.h
bar/
u.c
t.h
|
If your working directory is foo/bar and you compile with the command cc ../t.c -include t.h, the compiler includes t.h from foo/bar, not foo/ as would be the case with a #include directive from within the source file t.c.
If the compiler cannot find the file specified with -include in the current working directory, it searches the normal directory paths for the file. If you specify multiple -include options, the files are included in the order they appear on the command line.