Skip to content

Compiler preprocessor

Felipe Torrezan edited this page Aug 28, 2023 · 1 revision

The preprocessor runs before the compiler and is used to do textual insertion of header files (*.h and *.hpp), and definitions along with macro expansion. Relying on compiler-specific definitions, you can write source files that are conditionally compiled.

By default, a project created with the IAR Embedded Workbench will search for C/C++ header files in the toolchain's headers default locations ($TOOLKIT_DIR$/inc) as well as in the project directory ($PROJ_DIR$).

  • Open the project’s options with ProjectOptions (ALT+F7).
  • Navigate to the C/C++ CompilerPreprocessor tab.

In this tab, it is possible to specify Additional Include Directories: (one per line) here.

options-compiler-preprocessor

When one or more source folders are added to the project using the EWPtool, it will traverse the selected source folder(s) in search of header files. Then it will fill the C/C++ Preprocessor entries accordingly.

This tab also permits defining preprocessor symbols. If the original project uses Makefile or CMakeLists.txt, these might contain preprocessor definitions required by the application. Once you find them, it is just about bringing these symbols to the Defined Symbols box. For example:

project-options-compiler-preprocessor-symbols