# Can't find include file (Rebar3)

**URL:** <https://erlangforums.com/t/cant-find-include-file-rebar3/3460>\
**Category:** Questions / Help\
**Tags:** rebar3, erlang-otp\
**Created:** [April 5, 2024, 11:28pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460 "2024-04-05T23:28:43Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 5, 2024, 11:28pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/1 "2024-04-05T23:28:43Z")

</div>

Hello, all.

Could you explain how file inclusion actually works?

I have an umbrella project (Rebar3).  
Structure of folders:

```erlang
myproj = erl_app
├── apps
│ ├── c_app
│ └── erl_app
│ ├── c_src
│ ├── include %% | CASE 2
│ │ ├── erl_app.hrl %% | CASE 2
│ │ └── x.hrl %% | CASE 2
│ └── src
│ ├── some_folder
│ │ ├── x.erl
│ │ ├── x.hrl %% | CASE 3 WITHOUT INCLUDE FOLDER
│ │ └── x_server.erl
│ ├── myproj_app.erl
│ ├── myproj.app.src
│ ├── erl_app.hrl %% | CASE 3 WITHOUT INCLUDE FOLDER
│ └── myproj_sup.erl
├── config
├── doc
├── erlang_ls.config
├── include %% | CASE 1
│ ├── erl_app.hrl %% | CASE 1
│ └── x.hrl %% | CASE 1
├── LICENSE.md
├── priv
├── README.md
├── rebar.config
├── rebar.lock
└── test

```

According to this [7.4 Directory Structure](https://www.erlang.org/doc/design_principles/applications#directory-structure)

> `src` - _Required. Contains the Erlang source code, the source of the .app file and **internal include files used by the application itself**._  
> `include` - _Optional. Used **for public include files that must be reachable from other applications**._

The tree shows 3 cases for include files, one of which is actually used.  
**I have internal include files only.**  
**I am interested in the third case.**

According to this [10.1 File Inclusion](https://www.erlang.org/doc/reference_manual/macros#file-inclusion)

> _If the filename_ `File` _ **is absolute** (possibly after variable substitution), **the include file with that name is included.** Otherwise, the specified file is searched for in the following directories, and in this order:  
> 1. The current working directory  
> 2. The directory where the module is being compiled  
> 3. The directories given by the_ `include` _option_

According to this [Erlang Compiler](https://www.erlang.org/doc/man/compile)

> `{i,Dir}`  
> _Adds_ `Dir` _to the list of directories to be searched when including a file. When encountering an_ `-include` _or_ `-include_lib` \*directive, the compiler searches for header files in the following directories:  
> _1._ `"."`, _the current working directory of the file server  
> 2. The base name of the compiled file  
> 3. The directories specified using option_ `i` _; the directory specified last is searched first_

It is noted here [Erlang: what is the difference between “include\_lib” and “include”?](https://stackoverflow.com/questions/1847918/erlang-what-is-the-difference-between-include-lib-and-include)

> _One difference which is not obvious at first is that_ `-include` _and_ `-include_lib` _use a different set of paths when looking for header files._ `-include_lib` _ **in fact uses the code path, not the header file path.** _

**Configuration of the** `rebar.config` **file**

1 CASE

- Working case without `i` compiler option  
Open `x.erl` from `root_dir` i.e. `"."` of `myproj`

```erlang
-include("include/x.hrl"). % The filename File is absolute.

```

- Non-working case with `i` compiler option

```erlang
  1 {erl_opts, [debug_info,                                                         
  2                                                                           
  3 %% For internal include files used by the application itself.       
  4 %% Not the code path is used, but the header file path.             
  5 {i, ["include"]}                                                                  
  6 ]}.

```

```erlang
-include("x.hrl"). % E: can't find include file "x.hrl" 

```

2 CASE

- Working case without `i` compiler option  
Open `x.erl` from `root_dir` i.e. `"."` of `myproj`

```erlang
-include("apps/erl_app/include/x.hrl"). % The filename File is absolute.

```

- Non-working case with `i` compiler option

```erlang
  1 {erl_opts, [debug_info,                                                         
  2                                                                           
  3 %% For internal include files used by the application itself.       
  4 %% Not the code path is used, but the header file path.             
  5 {i, ["apps/*/include"]}                                                                  
  6 ]}.

```

```erlang
-include("x.hrl"). % E: can't find include file "x.hrl" 

```

3 CASE

- Working case without `i` compiler option  
Open `x.erl` from `root_dir` i.e. `"."` of `myproj`

```erlang
-include("apps/erl_app/src/some_folder/x.hrl"). % The filename File is absolute.

```

- Non-working case with `i` compiler option

```erlang
  1 {erl_opts, [debug_info,                                                         
  2                                                                           
  3 %% For internal include files used by the application itself.       
  4 %% Not the code path is used, but the header file path.             
  5 {i, ["apps/*/src", "apps/*/src/*"]}                                                                  
  6 ]}.

```

```erlang
-include("x.hrl"). % E: can't find include file "x.hrl" 

```

Since all 3 cases use `-include`, then `header file path` is used.

According to this [Code Path](https://www.erlang.org/doc/man/code#code-path)

> _Environment variable `ERL_LIBS` (defined in the operating system) can be used to define more library directories to be handled in the same way as the standard OTP library directory described above, except that directories without an `ebin` directory are ignored._

If I understood correctly, we can use `-include_lib` as it uses `search path` aka `code path`.  
For example, for the 2 CASE

- Working case without `i` compiler option  
Open `x.erl` from `root_dir` i.e. `"."` of `myproj`

```erlang
-include_lib("erl_app/include/x.hrl").

```

The explanation is here [10.1 File Inclusion](https://www.erlang.org/doc/reference_manual/macros#file-inclusion)

> _The code server uses_ `code:lib_dir(kernel)` _to find the directory of the current (latest) version of Kernel, and then the subdirectory_ `include` _is searched for the file_ `file.hrl`.

Only instead of `kernel`, you need to substitute `erl_app`.  
It should be noted that erl\_app should not hide app from `$OTPROOT/lib`, where `$OTPROOT` is the installation directory of Erlang/OTP.

**Result**  
Why is `{i,Dir}` not working (It works, but I don’t understand how.)?

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 2:34pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/2 "2024-04-06T14:34:10Z")

</div>

Hello, all.

For 3 CASE

```erlang
...
│ └── src
│ ├── some_folder
│ │ ├── x.erl
│ │ ├── x.hrl %% | CASE 3 WITHOUT INCLUDE FOLDER
│ │ └── x_server.erl
│ ├── myproj_app.erl
│ ├── myproj.app.src
│ ├── erl_app.hrl %% | CASE 3 WITHOUT INCLUDE FOLDER
│ └── myproj_sup.erl
...

```

Open `x.erl` from `root_dir` i.e. `"."` of `myproj`

```erlang
...
E 41 -include("x.hrl"). % E: can't find include file "x.hrl"    
...

```

But the project is being compiled (without `{i,Dir}`). This means that the corresponding file `x.hrl` is visible (without defining the absolute file name in the `-include()`). It can be concluded that directory `src` is viewed recursively, since the file is located in directory `some_folder`. However, the error msg is still being reported.

---

<div class="post-metadata">

**Author:** ![MononcQc](https://erlangforums.com/user_avatar/erlangforums.com/mononcqc/32/417_2.png) [@MononcQc](https://erlangforums.com/u/MononcQc)\
**Post date:** [April 6, 2024, 3:02pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/3 "2024-04-06T15:02:58Z")

</div>

First of all:

```erlang
-include("include/x.hrl"). % The filename File is absolute.

```

This is not an absolute path, that’s a relative path. An absolute path would look like this:

```erlang
-include("/home/username/somedir/include/x.hrl"). % The filename File is absolute.

```

This messes with your first assumption right away for the whole post. All these searches you make for the rest of the post are done with relative paths, and so will start with `./` (which is the project root for Rebar3), then the base name of the file (whatever source directory it has), and _then_ the `i` options.

Note that for Rebar3, you generally do not have to specify the `i` option for `include/` because Rebar3 will automatically expand them for you, and moreover, it will tend to do it with absolute directory paths for these areas, to avoid mistakenly getting mixed options across applications: [rebar3/apps/rebar/src/rebar\_compiler\_erl.erl at 9880ef3c7604724f8ea81daee1da6e92ccbf1167 · erlang/rebar3 · GitHub](https://github.com/erlang/rebar3/blob/9880ef3c7604724f8ea81daee1da6e92ccbf1167/apps/rebar/src/rebar_compiler_erl.erl#L28-L35) (there are also [a few tests checking that behavior](https://github.com/erlang/rebar3/blob/9880ef3c7604724f8ea81daee1da6e92ccbf1167/apps/rebar/test/rebar_compile_SUITE.erl#L2332-L2489)).

This is a thing we do to avoid messing with compilation contexts across large projects where dependencies might otherwise accidentally pick up the dependencies of their parent applications. This is a nefarious issue when a library author will write a thing that includes, say `include/user.hrl` and the parent project defines a `include/user.hrl` at the root of their project (the current working directory with `.`). What would happen here is that the library author writes a functional app that tests properly, but starts breaking when the user imports it because of unexpected include paths.

To make the library ecosystem more robust, we expand each lib’s relative includes to contain local paths, which prevents accidentally using the parent’s include files in a dependency’s build context within a complex umbrella application.

This sort of protective mechanism clashes with what Erlang documents and does outside the box, because we felt that providing repeatable builds where the user doesn’t have to debug or rewrite their app because they chose a header file name shared with a dep they didn’t write was more important.

However, this will also impact the sort of set-up you’ve done here if you’re trying to reach across these boundaries. So you have to consider new contextual elements:

- The current working directory (`"."`) is the root of the project as rebar3 does not `cd` into sub-applications during its build phases.
- the path names you have described as absolute are in fact relative
- rebar3 will expand the paths from the `{i, ...}` options to be _less relative_ and therefore _more specific_ to prevent accidentally breaking dependencies by defining header files with clashing names in their [unrelated] app.
  - note that while the `i` path is absolute, the `-include()` path may still be relative.

These are subtle but important changes that will no doubt mess with your scenarios here.

* * *

Now looking at your three cases:

**Case 1**

I’m not sure what you mean by " Open `x.erl` from `root_dir` i.e. `"."` of `myproj`". there is no x.erl at the root of the project; the `"include/x.hrl"` file should however be visible from the root.

`"x.hrl"` however is not a path that exists at the root of the project. That relative path _would_ be visible for `apps/erl_app/src/x.erl` if it declared `-include("x.hrl").` for example (which should grab `apps/erl_app/src/x.hrl`), but not the `include/x.hrl` at the project root.

**Case 2**  
I don’t believe `"apps/*/include"` makes sense as an `i` option.

You used `-include("apps/erl_app/include/x.hrl").` and it works, but it’s brittle. If you suddenly move ` erl_app` to say, `libs/`, it will break.

Here, using `-include_lib("erl_app/include/x.hrl").` will tell the build system to find `erl_app`’s `include/x.hrl` no matter where in the system that library is located (so long as it’s visible to the build tool).

It is therefore always a better idea to do it with `-include_lib()`, unless you’re somehow having multiple versions of the same app in your path and want to build one but include files from another.

**Case 3**

Same comment as for **Case 2** where I don’t think the directory syntax makes sense.

Note that in this case, `-include_lib(...)` would be inadequate because you’re trying to load a private header file (within `src/` rather than in `include/`) and that’s outside of conventions, so the use of `-include(...)` is adequate.

(The file path is still relative, it’s just properly defined as relative to the project root, which is where rebar3 executes from).

* * *

> Why is `{i,Dir}` not working (It works, but I don’t understand how.)?

Hopefully, the details I provided about how Rebar3 expands the paths to prevent cross-application clashes explains some of the confusing behavior you have noticed here. Also of note is that I don’t believe wildcards work in the path specifications, and all the options are _literal_.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 4:15pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/4 "2024-04-06T16:15:02Z")

</div>

Hello, Fred.

I am very grateful for the detailed explanation.

> _I’m not sure what you mean by " Open_ `x.erl` _from_ `root_dir` _i.e._ `"."` _of_ `myproj`".\*

I open `vim` in the current working directory (`"."`) i.e. the root of the project, then open the `x.erl` file using [nerdtree](https://github.com/preservim/nerdtree).

If I understood correctly, then in order for the error to go away, I must determine  
in `rebar.config` `{i, "/home/username/path/to/myproj/apps/erl_app/src/some_folder"}` % an absolute path  
in `x.erl` `-include("x.hrl")` % a relative path

The error msg does not go away.  
`E 41 -include("x.hrl"). % E: can't find include file "x.hrl"`

But the project is being compiled.

---

<div class="post-metadata">

**Author:** ![MononcQc](https://erlangforums.com/user_avatar/erlangforums.com/mononcqc/32/417_2.png) [@MononcQc](https://erlangforums.com/u/MononcQc)\
**Post date:** [April 6, 2024, 4:18pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/5 "2024-04-06T16:18:09Z")

</div>

> [@0m3](#):
>
> If I understood correctly, then in order for the error to go away, I must determine  
> in `rebar.config` `{i, "/home/username/path/to/myproj/apps/erl_app/src/some_folder"}` % an absolute path  
> in `x.erl` `-include("x.hrl")` % a relative path

no, `-include("x.hrl")` is a relative path _regardless of the `i` options_. If you want it to be absolute, it would need to be specified as `-include("/home/username/path/to/myproj/apps/erl_app/src/some_folder/x.hrl").`

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 4:30pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/6 "2024-04-06T16:30:35Z")

</div>

The error msg does not go away.  
I tried to move `x.hrl` from the `some_folder` to the `src` folder (one level higher) and made changes to the `rebar.config`, it still doesn’t go away.  
I  
`rebar.config`: `{i, "/home/username/path/to/myproj/apps/erl_app/src/some_folder/x.hrl"}.`  
`x.erl`: `E 41 -include("x.hrl"). % E: can't find include file "x.hrl"`  
II  
`rebar.config`: `{i, "/home/username/path/to/myproj/apps/erl_app/src/x.hrl"}.`  
`x.erl`: `E 41 -include("x.hrl"). % E: can't find include file "x.hrl"`

I open it via vim, via nerdtree.  
The project is still being compiled.

I still have `erlang_ls` installed. Maybe it has some effect?

---

<div class="post-metadata">

**Author:** ![MononcQc](https://erlangforums.com/user_avatar/erlangforums.com/mononcqc/32/417_2.png) [@MononcQc](https://erlangforums.com/u/MononcQc)\
**Post date:** [April 6, 2024, 4:43pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/7 "2024-04-06T16:43:07Z")

</div>

I don’t know that your editor opening the file has an impact, unless your editor is doing the building–I generally build all my projects by calling `rebar3 compile` in the terminal, which is fully disjoint from my editor or IDE.

If your editor does the compiling, then that’s an extra environment to debug for sure. If you have `erlang_ls` enabled, it may have an impact, because it might be the tool actually compiling the code and not `rebar3`.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 4:56pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/8 "2024-04-06T16:56:08Z")

</div>

I have `erlang_ls` installed, but I compile the code with the command `rebar3 compile`.  
There is an explanation in the vim below `E1516: can't find include file "x.hrl"`  
I checked it out

```erlang
❯ git clone https://github.com/erlang-ls/erlang_ls
❯ cd erlang_ls
❯ grep -HRs E1516 .
./apps/els_lsp/test/els_diagnostics_SUITE.erl: code => <<"E1516">>,
./apps/els_lsp/src/els_compiler_diagnostics.erl: <<"E1516">>;

```

I have a file `erlang_ls.yaml` in the root of the project.  
I have commented out all its contents, but there is no effect.  
`Vim` is used for editing code only.  
Maybe to reset the `erlang_ls` settings, it must be rebooted if it has any effect.  
If this does not help, then it is unclear what the root cause is.

`erlang_ls` settings:

```erlang
    1 #apps_dirs:                                                                                        
    2 # - "apps/*"                                                                   
>> 3 #deps_dirs:                                                                     
    4 # - "_build/default/lib/*"                                                     
    5 #include_dirs:                                                                  
    6 # - "apps"                                                                     
    7 # - "apps/*/include"                                                           
    8 # - "_build/default/lib/"                                                      
    9 # - "_build/default/lib/*/include"

```

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 5:13pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/9 "2024-04-06T17:13:42Z")

</div>

I rebooted PC. The same.  
This error message `E1516: can't find include file "x.hrl"` does not always appear.  
Now it is reported like this `can't find include file "x.hrl"`.

---

<div class="post-metadata">

**Author:** ![MononcQc](https://erlangforums.com/user_avatar/erlangforums.com/mononcqc/32/417_2.png) [@MononcQc](https://erlangforums.com/u/MononcQc)\
**Post date:** [April 6, 2024, 7:29pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/10 "2024-04-06T19:29:36Z")

</div>

I’m pretty sure that isn’t a rebar3 error, since we don’t number error messages.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 6, 2024, 7:55pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/11 "2024-04-06T19:55:57Z")

</div>

I changed the erlang version from 27.0-rc2 to 26.2.3 and completely disabled erlang\_ls. The same thing. Next, I changed the erlang version from 26.2.3 to 27.0-rc2 again and enabled erlang\_ls. The same thing. Now there is an error, but without a number.  
In the line of the directive `include()` in vim:

```erlang
E 41 -include("x.hrl"). % E: can't find include file "x.hrl"

```

At the very bottom in vim:

```erlang
 NORMAL  <c/some_folder/x.erl  erlang   utf-8   55% :41/74☰ ℅:1  23:00  E:4(L41) 
can't find include file "x.hrl"

```

I thought that maybe the absolute path was written incorrectly in the `rebar.config` file. I checked it several times. When typing, auto-completion is triggered. Maybe it’s not the rebar3 error. I don’t know why that is.  
I get so  
Whatever the directory structure, there is a `rebar.config` file and it contains the absolute path to the `.hrl` file and there is a source code file including a header file using the directive `-include()` that defines the relative path. The relative path should expand to the absolute path, but this does not happen.

`rebar.config`:

```erlang
  1 {erl_opts, [debug_info,                                                                              
  2 warn_export_vars, warn_shadow_vars, warn_obsolete_guard,            
  3 warn_missing_spec, warn_untyped_record,                             
  4                                                                                 
  5 %% For internal include files used by the application itself.       
  6 %% Not the code path is used, but the header file path.             
  7 {i, "/home/username/path/to/myproj/apps/erl_app/src/some_folder/x.hrl"}, % myproj = erl_app
  8 {i, "/home/username/path/to/myproj/apps/erl_app/src/erl_app.hrl"}        
  9 ]}.                                                                  
 10 {deps, []}.

```

`erlang_ls.yaml`:

```erlang
    1 apps_dirs:                                                                                         
    2 - "apps/*"                                                                    
>> 3 deps_dirs:                                                                      
    4 - "_build/default/lib/*"                                                      
    5 include_dirs:                                                                   
    6 - "apps"                                                                      
    7 - "apps/*/include"                                                            
    8 - "_build/default/lib/"                                                       
    9 - "_build/default/lib/*/include" 

```

Also, the name of my project matches the name of one of the erlang libraries.

```erlang
❯ asdf where erlang
/home/username/.asdf/installs/erlang/27.0-rc2
❯ ll /home/username/.asdf/installs/erlang/27.0-rc2/lib
total 136K
drwxr-xr-x 7 username username 4.0K Mar 21 20:17 asn1-5.3
drwxr-xr-x 7 username username 4.0K Mar 21 20:17 common_test-1.27
drwxr-xr-x 4 username username 4.0K Mar 21 20:17 compiler-8.5
...

```

Let’s say it’s like if my project was called `compiler`, but at least the versions don’t match. So I don’t think it should have any impact.

`vim ~/.vim/coc-settings.json`:

```erlang
   18 "erlang": {                                                             
   19 "command": "erlang_ls",                                             
   20 "filetypes": ["erlang"]                                             
   21 },  

```

```erlang
❯ rebar3 -v
rebar 3.22.0 on Erlang/OTP 27 Erts 14.3
❯ erlang_ls -v
Version: 0.49.0
❯ asdf current
erlang 27.0-rc2 

```

Sometimes (when switching to the previous version and back) on version 27.0-rc2, this appears during compilation:

```erlang
===> Analyzing applications...                                                                                                                                                                                      
===> Compiling pc                                                                  
===> Compiling ../../../../.cache/rebar3/plugins/pc/src/pc_port_env.erl failed  
../../../../.cache/rebar3/plugins/pc/src/pc_port_env.erl:190:10: code:lib_dir/2 is deprecated; this functionality will be removed in a future release
                                                                                   
===> Errors loading plugin pc. Run rebar3 with DEBUG=1 set to see errors.

```

It helps  
`rebar3 as global plugins upgrade pc`

Global rebar3 config `vim ~/.config/rebar3/rebar.config`:

```erlang
1 {plugins, [rebar3_auto, rebar3_ex_doc]}.

```

Additionally, 3 plugins have been removed from `.vimrc`:

```erlang
   52 "Plug 'vim-erlang/vim-erlang-omnicomplete' " autocompletion                     
   53 "Plug 'vim-erlang/vim-erlang-compiler' " syntax checking and compiler                              
   54 "Plug 'vim-erlang/vim-erlang-runtime' " indentation, syntax and ftplugin scripts

```

And the `rebar3` cache has been cleared:

```erlang
❯ rm -r ~/.cache/rebar3

```

The error msg does not go away.

---

<div class="post-metadata">

**Author:** ![MononcQc](https://erlangforums.com/user_avatar/erlangforums.com/mononcqc/32/417_2.png) [@MononcQc](https://erlangforums.com/u/MononcQc)\
**Post date:** [April 6, 2024, 11:42pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/12 "2024-04-06T23:42:09Z")

</div>

Here’s a demo app showing all the kinds of include paths you may want, with zero extra config: [GitHub - ferd/incl\_chk: a demo repo for a forum discussion](https://github.com/ferd/incl_chk)

```erlang
.
├── a.hrl
├── apps
│ ├── alt
│ │ ├── include
│ │ │ └── g.hrl
│ │ └── src
│ │ ├── alt.app.src
│ │ ├── alt.erl
│ │ └── h.hrl
│ └── incl_chk
│ ├── include
│ │ └── c.hrl
│ └── src
│ ├── d.hrl
│ ├── incl_chk_app.erl
│ ├── incl_chk.app.src
│ ├── incl_chk_sup.erl
│ └── sub
│ ├── chk.erl
│ ├── e.hrl
│ └── f.hrl
├── config
│ ├── sys.config
│ └── vm.args
└── include
    └── b.hrl

```

See [`incl_chk/apps/incl_chk/src/sub/chk.erl`](https://github.com/ferd/incl_chk/blob/main/apps/incl_chk/src/sub/chk.erl):

```erlang
-module(chk).
-export([f/0]).

-include("a.hrl").
-include("include/b.hrl").
-include("include/c.hrl").
-include("d.hrl").
-include("sub/e.hrl").
-include("f.hrl").
-include_lib("alt/include/g.hrl").
-include("apps/alt/src/h.hrl").

f() ->
    [?A, ?B, ?C, ?D, ?E, ?F, ?G, ?H].

```

Run with:

```erlang
→ rebar3 shell --apps=
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling incl_chk
===> Compiling alt
Erlang/OTP 26 [erts-14.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Eshell V14.0 (press Ctrl+G to abort, type help(). for help)
1> chk:f().
[a,b,c,d,e,f,g,h]

```

This works out of the box.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 7, 2024, 12:22am UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/13 "2024-04-07T00:22:25Z")

</div>

Thank you very much, Fred. I will try.

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [April 7, 2024, 1:32pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/14 "2024-04-07T13:32:37Z")

</div>

> [@0m3](#):
>
> `erlang_ls.yaml`:

File should be named `erlang_ls.config`, not `erlang_ls.yaml` - maybe your `erlang_ls` config is not even used. How you can trivially check that is to inject syntax error in that yaml format - if it gets reported during erlang\_ls startup then config is used, if it doesn’t than your configuration is not used by erlang\_ls.

If you get error messages from your LSP client in vim, it doesn’t have to be that the project doesn’t compile. You can get error messages from LSP client and be able to compile a project. You can also have no errors from LSP, but project could not compile.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 7, 2024, 4:10pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/15 "2024-04-07T16:10:49Z")

</div>

Hello, all.

For @mmin:

> _"File should be named_ `erlang_ls.config`, _not_ `erlang_ls.yaml`_"_

According to [erlang\_ls configuration](https://github.com/erlang-ls/erlang_ls?tab=readme-ov-file#configuration):

> _It is possible to customize the behaviour of the_ `erlang_ls` _server via a configuration file, named_ `erlang_ls.config` _or_ `erlang_ls.yaml`.

Thanks a lot, @MononcQc for the [GitHub - ferd/incl\_chk: a demo repo for a forum discussion](https://github.com/ferd/incl_chk).

I experimented with the demo. The results are as follows:  
I use vim and some set of plugins.  
If open `vim` in the current working directory (`"."`) i.e. the root of the project, then open [`incl_chk/apps/incl_chk/src/sub/chk.erl`](https://github.com/ferd/incl_chk/blob/main/apps/incl_chk/src/sub/chk.erl) file using [nerdtree](https://github.com/preservim/nerdtree) then

 ![ink01](https://erlangforums.com/uploads/default/original/2X/7/76b2aa92e122f1d8e6a3c7085ffade7305743b15.jpeg)  
According to what @MononcQc said above:

> _I’m pretty sure that isn’t a_ `rebar3` _error, since **we don’t number error messages**._

In the same window, let’s go down a little lower

 ![ink02](https://erlangforums.com/uploads/default/original/2X/5/5ae3a755e7bb97f632c2620247f6b84aa0dc1445.jpeg)  
We see that the error is already without a number, but we do not yet know what is causing it. Ok.

Disable reporting in-line warnings and errors from the Erlang [compiler](https://erlang.org/doc/man/compile.html). Description here [erlang\_ls-configuration-diagnostics](https://erlang-ls.github.io/configuration/):  
Add in the `erlang_ls.yaml` file:

```erlang
1 diagnostics:                                                                                         
2 disabled:                                                                     
3 - compiler

```

Let’s open `vim` in the current working directory (`"."`) i.e. the root of the project, then open [`incl_chk/apps/incl_chk/src/sub/chk.erl`](https://github.com/ferd/incl_chk/blob/main/apps/incl_chk/src/sub/chk.erl) file using [nerdtree](https://github.com/preservim/nerdtree) again

 ![ink03](https://erlangforums.com/uploads/default/original/2X/4/408e502eb077e42313d4da611004d0e088d89e06.jpeg)  
We can see that on line 6 there is an error message with no number already. Ok.

Now turn off the plugin [ALE (Asynchronous Lint Engine)](https://github.com/rchicoli/vim-ale)  
Add to `.vimrc`:

```erlang
...
67 let g:ale_enabled = 0
...

```

Let’s open `vim` in the current working directory (`"."`) i.e. the root of the project, then open [`incl_chk/apps/incl_chk/src/sub/chk.erl`](https://github.com/ferd/incl_chk/blob/main/apps/incl_chk/src/sub/chk.erl) file using [nerdtree](https://github.com/preservim/nerdtree) again

 ![ink04](https://erlangforums.com/uploads/default/original/2X/e/e52b8530f9f126b429f568b48504ec97b10de0dc.jpeg)

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 7, 2024, 4:27pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/16 "2024-04-07T16:27:54Z")

</div>

Thanks to everyone who took the time to look at and answer the question.

BR, Denis.

---

<div class="post-metadata">

**Author:** ![0m3](https://erlangforums.com/user_avatar/erlangforums.com/0m3/32/2339_2.png) [@0m3](https://erlangforums.com/u/0m3)\
**Post date:** [April 9, 2024, 5:57pm UTC](https://erlangforums.com/t/cant-find-include-file-rebar3/3460/17 "2024-04-09T17:57:15Z")

</div>

Hello, all.

# Minimal Erlang Integration for this case

## [ALE](https://github.com/dense-analysis/ale)

Add to the Vim configuration file `~/.vimrc`

```erlang
" === ale ===                                                                      
"ALE Erlang Integration:                                                           
"Enable only a particular set of linters for erlang files.                         
let g:ale_linters = {                                                              
\ 'erlang': ['dialyzer', 'erlang_ls', 'erlc']                                    
\}                                                                                 
let g:ale_erlang_erlc_options = "$(find apps -type d -exec echo '-I {}' ';')" 

```

Run `:ALEInfo` to see which linters are available after telling ALE to run Erlang linters.  
For more information, see [Vim help files for ALE](https://github.com/dense-analysis/ale/tree/master/doc) and in particular [Erlang-specific Vim help file for ALE](https://github.com/dense-analysis/ale/blob/master/doc/ale-erlang.txt).

## [coc.nvim](https://github.com/neoclide/coc.nvim)

Add to the `coc.nvim` configuration file `~/.vim/coc-settings.json`:

```erlang
{
      "languageserver": {                                                            
          "erlang": {                                                                
              "command": "erlang_ls",                                                
              "filetypes": ["erlang"]                                                
         }                                                 
      },                                                                                                 
      "diagnostic.displayByAle": true                                                
  }  

```

For more information, see [Coc plugin configuration](https://erlang-ls.github.io/getting-started/vim/) and [The easiest way to get both plugins (`coc.nvim` + `ale`) to work together](https://github.com/dense-analysis/ale?tab=readme-ov-file#cocnvim).

## [erlang\_ls](https://github.com/erlang-ls/erlang_ls)

Add to the `erlang_ls.yaml` or `erlang_ls.config` configuration file:

```erlang
apps_dirs:                                                                      
  - "apps/*"                                                                    
deps_dirs:                                           
  - "_build/default/lib/*"                                                                             
# These paths are prepended to all other paths  
# given by an -include or -include_lib directive.                                 
include_dirs:                                                                      
  - "apps"                                                                         
  - "apps/*"                                                                       
  - "apps/*/src"                                                                   
  - "_build/default/lib/"                                                          
  - "_build/default/lib/*/include"  

```

For more information, see [erlang\_ls configuration](https://github.com/erlang-ls/erlang_ls?tab=readme-ov-file#configuration).

Tested on [GitHub - ferd/incl\_chk: a demo repo for a forum discussion](https://github.com/ferd/incl_chk).
