Directories for code inside the sketch directory

Hi,

I wanted to have a directory structure like:

sketch
|
+-- code.ino
|
+--src
|
+-- cool_library
| |
| +-- thing.hpp
| +-- thing.cpp
|
+-- helper
| |
| +-- helper.hpp
| +-- helper.cpp

This works ok.

I found on some forum posts that code must go in a src directory so that solved my first issue but I cant find an answer to the following.

In code.ino I can include things like #include "src/cool_library/thing.hpp"

My problem is when the code in the folder needs a header from another folder.

For example if I want to use helper from thing.hpp i have to include like: #include "../helper/helper.hpp"

I don't like this and would like to be able to do: #include <src/helper/helper.hpp>

It would be really nice if sketch (or src) was setup as an include directory. Is it possible to do this or is there another better way?

Is it possible to do this

No. When the helper.cpp file is compiled, the preprocessor knows only the relative path (./src/helper) to the source files. Any other files it needs need to be defined relative to that path.

is there another better way?

You have a way that works. What could be better than that?

Of course, you do not have to use the IDE with it's restrictions. You are free to invoke the compiler and linker directly, with the resulting full control over the arguments (and the restrictions of having to manually supply all those arguments).

Ahh I thought as much, thanks for the answer.

The reason I wanted to change was because I changed the directory of a library and that meant all the includes were wrong. If the “include_directories” was set to src it would have been fine (obviously if something included the moved file that include will need changed regardless)

There's a feature request for this here:

and what looks like some work to add the feature, but perhaps limited to one particular case, here: