PIO compiler says no such file or directory when file clearly exists

Ive been having the “No such file or directory” issue for quite some time in PlatformIO extension with VScode when its never been an issue in Visual Studio. (not VScode)

I require a config file to be included in several libraries and other sources. My project setup is as follows:

MyProject
|-include
| |-config.h
|-lib
| |-LibraryA
| | |-libraryA.h
| | |-libraryA.cpp
| |-LibraryB
| | |-libraryB.h
| | |-libraryB.cpp
|-src
| |-main.cpp

Now, if I include config.h in main.cpp all is well. But if I include config.cpp in LibraryA/B.h or LibraryA/B.cpp I get the “No such file or directory” compiling error.

Why is this? If I right click #include "config.h" and select “Go to References” it takes me to the config file, or I can “Tab” autocomplete when typing in config.h it does so successfully too. So it knows the header file exists. Why can the linker not find it?

Is there a way to change the include statement to navigate from one library directory, such as LibraryA.cpp to something like #include “MyProject/include/config.h”?

Any help would be greatly appreciated.
Thank you

I finally found the solution in another thread: PIO library doesn't see header files in project's include folder - #6 by geoffreyottoy

To summarize: all files in src and include folders are not global. The linker cannot know of the existence of these files, even if intellisense (which is not the same as the linker which is not the same to the compiler) knows its reference.

To solve this problem add the following line to the platform.ini file.
build_flags = -I include

This will make the content of the include folder visible

As far as I understand it, it’s by design: the main project will depend on libraries but the libraries should not depend on the main project.

An alternative solution to what @mishahartmann has proposed is to create a config library (within the lib folder) and put config.h there.

That is correct since by default when building unit tests src/ is not built (unless flag is passed in)