NOTICE: This website will be shut down in the near future. Product content has moved to nxp.com. Forum content and FAQs have been moved to community.nxp.com. We encourage you to create a user account on nxp.com to use the new community forums and access NXP microcontroller content. We greatly appreciate your contributions and look forward to seeing you at our new web location.

 

How include paths work

lpcxpresso-support's picture

When you add a directory under the "Directories" section of the compiler, you are setting the compilers "-I" option.

"-I" adds a directory to the compiler search path for include files. When the compiler tries to locate header files, it will search each directory in the search path for the exact filename provided in the #include directive.

For example, if your project contains the following directory structure (at the root of the project):

my_headers
  my_header.h
  sub_dir
     my_sub_header.h

You can add the following to the "Directories" compiler setting

  • "../my_headers" ('../' is required as projects are built in a subdirectory of the project root)

In your source, you can:

    #include "my_header.h"
    #include "sub_dir/my_sub_header.h"

Alternatively, you can add the following to the "Directories" compiler setting

  • "../my_headers"
    "../my_headers/sub_dir" ('../' is required as projects are built in a subdirectory of the project root)

In your source, you can:

    #include "my_header.h"
    #include "my_sub_header.h"

In LPCXpresso IDE, you can specify Include and Library paths as:

  • absolute paths
    • e.g. c:/path/to/directory
  • relative paths
    • e.g. ../relative/directory
  • workspace path
    • e.g. ${workspace_loc:/project/path}
  • path based on an environment variable
    • e.g. ${env_var:ENVIRONMENT_VARIABLE}/path

NOTE: You should take care to always use forward slashes in paths specifications even when on Windows, i.e. use / not \ .

5
Your rating: None Average: 5 (1 vote)
feedback