I have main.c and main.h files in the src directory (VSCode project for ESP32 Dev). Everything works fine, project builds, it just works.
But I’d like the header files to be in a different directory than the source files, like include. With this, I have so far been unsuccessful. Moving the header to include was recognised by VSCode, but the building failed, telling me that pretty much everything is undefined. lib acted just the same. I tried putting build_flags = -I include to platformio.ini or include_dir = include, but the effect was always the same (and yes, every attempt, I did remove the .pio directory).
I tried to look for solution here but I either just got more confused or the issue was relevant to IDE errors – VSCode recognises the header files and Intellisense works just fine, the build system doesn’t.
Correct, .c/.cpp files in include/ are not compiled ("added to the build system to produce a .o object file that will be linked in the final .elf).
…but doesn’t say what to do about it. Do I just have to go with it and make a src/include directory, if I want the headers, ex. main.h, included with main.c? What’s the point of include directory then?
EDIT: Okay, just randomly it started behaving differently. With the build_flag = -I include thing, it seems to recognise the headers (I think?) but I am getting new errors about the ESP headers not being recognised:
In file included from /home/onegen/.platformio/packages/framework-espidf/components/wpa_supplicant/port/eloop.c:16:
include/common.h:12:10: fatal error: driver/gpio.h: No such file or directory
12 | #include "driver/gpio.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
Same problem occurs if I try the src/include thing.
Hello Everyone, New here.
I am trying out PIO with VS Code on windows, and all I want to do right now is include the gpio.h file without having to first copy it into the include folder in my project dir.
here is the error I keep getting:
src\main.c:1:10: fatal error: driver/gpio.h: No such file or directory
1 | #include “driver/gpio.h”
| ^~~~~~~~~~~~~~~
compilation terminated.
Any help with setting up PIO would be greatly appreciated.
also, $pio run returns a not recognized as an internal or external command message.
Based on the tags you have chosen, i suppose you’re making an ESP-IDF project.
Usually there is no need to copy header files which are part of the esp-idf framework into the include folder because they are already “builtin”.
A simple #include "driver/gpio.h" should work (and does for me).
My experience after setting up a fresh ESP-IDF project:
After adding the #include "driver/gpio" to main.cpp, it took a momment and a required a restart of VS Code to work correctly.
But maybe I didn’t wait long enough and the restart is probably unnecessary.
After that the file was processed by IntelliSync without any problems.
In any case, a compilation error should never occur. Then there really seems to be something wrong with the installation. Perhaps the framework was not yet fully installed?
I have worked with PIC processors for year, but this is my first time jumping into ESP. I expect the driver/gpio.h include to work, according the resources online, and the ESP development manual i have, however, it is not. do I need the ESP32 device connected to compile? and can you point me to an install guide? so I could try reinstalling.
ESP-IDF project.
I have also reinstalled PIO following the official documentation and nothing changed. I also tried an arduino project, and IDE returned the same error for #include “Arduino.h”: No such file or directory gcc.