ESP32 library issues

Hi everyone.

This thing is kinda a rabbit hole here for me. Hope everyone is cool with it.

I’ve begin to need to use PlatformIO to enable using the the “ESP32 ESP8266 Exception Decoder”. There were some errors which the Arduino IDE wasn’t equipped with to help me with the issue.

And so, I began dabbling with PlatformIO via VSCode, by importing the .ino file built in the Arduino IDE.

The problem is, now I’m having a bunch of issues cropping up (as with many migration issues I suppose). But well, I think I’ll begin with a simple one first and build my way through it all.

So the issue is: the output returns “cannot open source file “Arduino.h”” after running the code.

I believe there is a method to properly edit the include files, but the solutions I followed in this forum before this maybe wasn’t the suitable one.

Here’s the code:

#include <Arduino.h>

#define Indicator 2

void setup() {
  pinMode(Indicator, OUTPUT);

void loop() {



.ino does not have good intellisense. I’d recommend conversion to .cpp as the docs state.

If the compiler keeps having problems with Arduino.h not found, then try triggering a package reinstall by deleting C:\Users\<user>\.platformio\packages and restarting VSCode.

1 Like

Hi Max. I started from scratch, without importing the .ino this time.

I did it all and still to no avail. Deleted, restarted. The “packages” folder reinstated itself as expected after deletion, and the Arduino.h squiggles disappeared. And yet, it says “no such file/directory.”

Is there anything else I could check?

Do not use the play button in the upper right corner of VSCode. This “Build” button does not belong to PlatformIO and will try to compile a Arduino program with the compiler for your local computer (which makes no sense when trying to compile for an embedded device).


You have to follow the the the documentation and use the right build button, which is either the checkmark in the bottom taskbar


or the Alien / Ant sidebar icon and the “build” project task button.

Bot of this is already documented in


1 Like

Ouch that was embarassing. Thanks, it worked nicely!

Hm, actually this problem does have some history to it. PlatformIO extension tried to protect users from that exact wrong button with the "C_Cpp.debugShorcut": false configuration in over a year ago. After that fix, the button was gone.

What I see now though even on my installation is that it’s not gone, but, it correctly maps to the PlatformIO build options.

I think a conflicting extension of configuration breaks it for you.

Can you

  1. Delete the .vscode folder of the project and restart VSCode. Does the upper right build button work now?
  2. Give the full list of installed extensions (extensions sidebar)

Mine are:

1 Like

Hi Mark.

Yeah, I’ve deleted the .vscode and now it only points to the Run Code option. Nice trick!

Here’s my list of extensions:

Now since I’m already starting to get to the nitty gritty, a new issue cropped. How do I properly place a header file for a separate header file similar to Arduino?

Because an instance like this, if I included the following header file in my main.cpp:

#include <Arduino.h>
#define Indicator 2

void Alert(int freq) {

  for (int x = 0; x < freq; x++) {
    digitalWrite(Indicator, HIGH);
    digitalWrite(Indicator, LOW);

  digitalWrite(Indicator, LOW);

As a separate .cpp file (I’ve read that we’ve got to refer them as .cpp) and it produces the following error:

c:/users/user_name/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\esp-wrover-kit\src\main.cpp.o: in function Alert(int):
C:\Users\User_Name\Documents\PlatformIO\Projects\Your_Project/src/Virspect.cpp:6: multiple definition of Alert(int); .pio\build\esp-wrover-kit\src/Virspect.cpp.o:C:\Users\User_Name\Documents\PlatformIO\Projects\Your_Project/src/Virspect.cpp:6: first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp-wrover-kit\firmware.elf] Error 1

Edit: Aaaaargh nevermind. I found out i have to put it in the include folder

It turns out my problem was pointed out in VSCode early on, which is something that the Arduino IDE couldn’t address. I was writing my API function incorrectly, which still compiled, which caused the crash to occur every time.

Platform IO rocks!