Skip to main content

IAR Embedded Workbench for RISC-V 3.40

Include file search procedure

In this section:

This is a detailed description of the compiler’s #include file search procedure:

  • The string found between the "" and <> in the #include directive is used verbatim as a source file name.

  • If the name of the #include file is an absolute path specified in angle brackets or double quotes, that file is opened.

  • If the compiler encounters the name of an #include file in angle brackets, such as:

    #include <stdio.h>

    it searches these directories for the file to include:

    1. The directories specified with the -I option, in the order that they were specified, see -I.

    2. The directories specified using the C_INCLUDE environment variable, if any, see Environment variables.

    3. The automatically set up library system include directories. See ‑‑dlib_config.

  • If the compiler encounters the name of an #include file in double quotes, for example:

    #include "vars.h"

    it searches the directory of the source file in which the #include statement occurs, and then performs the same sequence as for angle-bracketed filenames.

If there are nested #include files, the compiler starts searching the directory of the file that was last included, iterating upwards for each included file, searching the source file directory last. For example:

src.c in directory dir\src
	#include "src.h"
	...
src.h in directory dir\include
	#include "config.h"
	...

When dir\exe is the current directory, use this command for compilation:

iccriscv ..\src\src.c -I..\include -I..\debugconfig

Then the following directories are searched in the order listed below for the file config.h, which in this example is located in the dir\debugconfig directory:

dir\include

Current file is src.h.

dir\src

File including current file (src.c).

dir\include

As specified with the first -I option.

dir\debugconfig

As specified with the second -I option.

Use angle brackets for standard header files, like stdio.h, and double quotes for files that are part of your application.

Note

Both \ and / can be used as directory delimiters.

For more information, see Overview of the preprocessor.