Debian Codegraph @

subprojects/meson-docs/docs/markdown/Include-directories.md

raw
1 ---
2 short-description: Instructions on handling include directories
3 ...
4
5 # Include directories
6
7 Most `C`/`C++` projects have headers in different directories than
8 sources. Thus you need to specify include directories. Let's assume
9 that we are at some subdirectory and wish to add its `include`
10 subdirectory to some target's search path. To create a include
11 directory object we do this:
12
13 ```meson
14 incdir = include_directories('include')
15 ```
16
17 The `incdir` variable now holds a reference to the `include` subdir.
18 Now we pass that as an argument to a build target:
19
20 ```meson
21 executable('someprog', 'someprog.c', include_directories : incdir)
22 ```
23
24 Note that these two commands can be given in any subdirectories and it
25 will still work. Meson will keep track of the locations and generate
26 proper compiler flags to make it all work.
27
28 Another thing to note is that `include_directories` adds both the
29 source directory and corresponding build directory to include path, so
30 you don't have to care. If it turns out you don't want it after all, this can
31 be disabled with the `implicit_include_directories` argument to the [build
32 function](Reference-manual_functions.md) you use.