Sublime Linter with clang can't find header file in header

495 Views Asked by At

I'm using sublime text with the sublime linter plugin especially with clang.

When I open a folder, it use the root of the folder as a header location, so if I have

src
├── World
│   ├── Chunk.cpp
│   ├── Chunk.hpp
│   ├── World.cpp
│   └── World.hpp
└── main.cpp

In World.cpp I need to include "World/World.hpp".

But if in World.hpp I include Chunk.hpp the same way ("World/Chunk.hpp"), I get an error but in World.hpp I have no error. Error are only in file I include that include other file.

1

There are 1 best solutions below

0
h_uat On

I had the same issue. You need to tell clang where to look for the files, i.e. which directories you want to include. Go Preferences --> Package Settings --> SublimeLinter --> Settings and add a new section for clang++:

// SublimeLinter Settings - User
{
    "linters":
    {
        "clang++": {
            "I" : [
                "${folder}/src",
                "${file_path}",

            ]
        }
    }
}

In your case the two include directories will actually point to the same path but in general, the first version is to include your source directory (e.g. you have a unit test from a different folder open which accesses code from you src directory) and the second line includes the location of your current file.

If you need different directories, find some more variables you can use here.