Search code examples
visual-studio-codelinkerincludeplatformio

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)

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?

Any help would be greatly appreciated. Thank you


Solution

  • I finally found the solution. 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