PlatformIO Community

Error including <Arduino.h>

I see that this has already been asked a few times, but this issue I’m having seems unique enough to warrant a new post.

I’ve just recently decided to try using PlatformIO for my ESP32 Arduino project. To get things started, all I did was install the VSCode extension and create a new project. However, the initial project that was generated gave me an include error: unable to open Arduino.h. After a bit of googling, I found a suggestion that said to erase the .vscode directory and then restart VSCode. Did that and then noticed the include error – this time, Intellisense is giving the error cannot open source file "algorithm" (dependency of "Arduino.h") After seeing this, I checked the include path of the compiler (echo | xtensa-esp32-elf-gcc -E -Wp,-v -) and then checked the include paths listed there – I found the algorithm file at /home/me/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/extensa-esp32-elf/xtensa-esp32-elf/include/c++/algorithm. The file is definitely there, but Intellisense doesn’t seem to recognize it!

I copied the file to my project’s include/ directory to see if that would solve the issue, but lo and behold, Intellisense now cannot find source file "utility"! I’d much prefer not to have to copy stdlib headers every time Intellisense starts complaining, so does anybody have an idea on how to resolve this?

Some info about my setup:

VSCode extensions: C/C++ (Microsoft), PlatformIO IDE, some Theme extensions, Vim emulator (vscodevim)

pio --version: PlatformIO, version 4.2.1a1

$ pio settings get
Name                       Current value [Default]                     Description
-------------------------  ------------------------------------------  --------------------------------------------------------
auto_update_libraries      No                                          Automatically update libraries (Yes/No)
auto_update_platforms      No                                          Automatically update platforms (Yes/No)
check_libraries_interval   7                                           Check for the library updates interval (days)
check_platformio_interval  3                                           Check for the new PlatformIO interval (days)
check_platforms_interval   7                                           Check for the platform updates interval (days)
enable_cache               Yes                                         Enable caching for API requests and Library Manager
enable_telemetry           Yes                                         Telemetry service <http://bit.ly/pio-telemetry> (Yes/No)
force_verbose              No                                          Force verbose output when processing environments
projects_dir               /home/colton/Documents/PlatformIO/Projects  Default location for PlatformIO projects (PIO Home)
strict_ssl                 No                                          Strict SSL for PlatformIO Services

code --version: 1.42.0

src/main.cpp

#include <Arduino.h>
void setup(){}
void loop(){}

There is no point in modifying c_cpp_properties.json as it is automatically generated by PlatformIO and will be overwritten without warning.

The algorithm header file should be in the directory /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0 and should be found without adding it to c_cpp_properties.json as it is part of the compiler installation.

Try the following steps:

  • Make sure the project can be successfully built despite the warnings in the editor
  • Make sure your project path or PlatformIO installation path doesn’t contain any spaces or special characters (as Visual Studo Code’s IntelliSense is unable to deal with it)
  • Close all editor views in Visual Studio Code and quit VSC
  • Delete .vscode within your project folder again (as you have modified it)
  • Open Visual Studio Code again
  • Within Visual Studio, open main.cpp from the Explorer view
  • .vscode should now be recreated and after a few seconds the warning in the editor should go away

If you still have problems, post your platformio.ini file and information about the platform you are using (macOS?).

Thanks for responding.

I didn’t make any edits to any files (except main.cpp, to consolidate – other than that, this project is entirely default). I simply copied the Algorithm file to the include directory (I didn’t add it to c_cpp_properties.json include path since I knew it was auto-generated, as I had deleted the .vscode directory before and the file was re-created).

I’ve followed your steps. The project compiles, but Intellisense is still complaining about not being able to open the algorithm file (since I’ve removed it from include/).

platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

I’m running 64-bit Ubuntu 18.04 LTS

Ok, I get now what you did with the include file.

Can you try these steps:

1 Like

Here’s the output you asked for. The character count exceeded the forum’s max character count so I had to put it in a gist.

https://gist.github.com/donnellycolton/8ce3836c28dac8910258aa7a0e46f8e4

When comparing your log with a similar log on my machine (for basically the same ESP32 project), its very similar. But one thing pops out. Your log contains these lines (line 327 – 332):

  include: /home/colton/include
  include: /usr/lib/gcc/x86_64-linux-gnu/7/include
  include: /usr/local/include
  include: /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
  include: /usr/include/x86_64-linux-gnu
  include: /usr/include

While mine log contains these lines in exactly the same place (related to analyzing file main.cpp):

  include: /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0
  include: /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/xtensa-esp32-elf
  include: /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/backward
  include: /home/me/.platformio/packages/toolchain-xtensa32/lib/gcc/xtensa-esp32-elf/5.2.0/include
  include: /home/me/.platformio/packages/toolchain-xtensa32/lib/gcc/xtensa-esp32-elf/5.2.0/include-fixed
  include: /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include
  include: /home/me/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/sysroot/usr/include

So it looks like the wrong compiler is picked in your case (64 bit x86 instead of 32 bit xtensa).

I’m not sufficiently familiar with the inner workings of VSC and PIO. Maybe somebody else has an idea what the reason could be?

Can you also post your c_cpp_properties.json file. It contains the path to the compiler…

Here’s the c_cpp_properties.json file. The intellisense mode seems to be using 64-bit clang, but the compiler triple from compilerPath does specify the xtensa esp32 compiler

https://gist.github.com/donnellycolton/c3d116f9bc20ec69430719b943281f10

Your file looks like mine (expect for username and similar stuff). Mine says "intelliSenseMode": "clang-x64" as well.

I’m a bit lost here…

@valeros Do you have an idea why the system header files from the x86_64 compiler are used instead of from the xtensa-esp32 compiler (see post #6).

Gave it a second longer of thought…

Those directories are part of the gcc include path. I was having an issue where Intellisense wasn’t including header files that weren’t in an include path I was having gcc use (I set CPATH to include /home/colton/include). Because Intellisense was ignoring those headers, I had the idea of adding to Intellisense’s default include path. The instructions are here.

After thinking a little bit about #6 I remembered I had done this, deleted the changes, and voila, PlatformIO works! I have no idea why this was causing issues, but thank you so much for helping me figure this out!

1 Like

The problem might be that it’s not adding, but overriding? A quick test on my end seems setting "C_Cpp.default.includePath" suggested absolutely nothing to the intellisense processing - didn’t add or change the folders processed as far as I could see, but that seems at odds with the first thing it says on that page:

You can override the default values for properties set in c_cpp_properties.json .

It looks like you need to add "${default}" to the parameter in c_cpp_properties.json if you want it to add the values configured via those flags… not sure how you would do that with PIO though, maybe by missusing the -Idir build_flags?

Do you know what specific settings you changed? Maybe it’s only one particular one that mucks things up, and could be a bug that needs reporting back to the VSCode C/C++ extension team.

A quick test of an ESP32 project shows I have the same behaviour as @manuelbl - toolchain-extensa32 lines after tool-unity…

cpptools/activeDocumentChange
cpptools/textEditorSelectionChange
cpptools/getDocumentSymbols: 3
cpptools/getDocumentSymbols
sending compilation args for /media/2TB_upper/repos/GitHub/ESP32-Radio/Esp32_radio/Esp32_radio.cpp
  include: /media/2TB_upper/repos/GitHub/ESP32-Radio/Esp32_radio
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/SD/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/FS/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/ArduinoOTA/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/Update/src
  include: /media/2TB_upper/repos/GitHub/ESP32-Radio/.pio/libdeps/mhetesp32minikit/Adafruit ST7735 and ST7789 Library_ID12
  include: /media/2TB_upper/repos/GitHub/ESP32-Radio/.pio/libdeps/mhetesp32minikit/Adafruit ILI9341_ID571
  include: /media/2TB_upper/repos/GitHub/ESP32-Radio/.pio/libdeps/mhetesp32minikit/Adafruit GFX Library_ID13
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src
  include: /media/2TB_upper/repos/GitHub/ESP32-Radio/.pio/libdeps/mhetesp32minikit/PubSubClient_ID89/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_trace
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_update
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/asio
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bootloader_support
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/bt
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/coap
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/console
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/driver
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-tls
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_adc_cal
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_event
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_client
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_http_server
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_https_ota
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp_ringbuf
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ethernet
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/expat
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fatfs
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freemodbus
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/freertos
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/heap
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/idf_test
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/jsmn
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/json
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/libsodium
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/log
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/lwip
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mbedtls
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mdns
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/micro-ecc
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/mqtt
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/newlib
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nghttp
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/nvs_flash
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/openssl
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protobuf-c
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/protocomm
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/pthread
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/sdmmc
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/smartconfig_ack
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/soc
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spi_flash
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/spiffs
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcp_transport
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/tcpip_adapter
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/ulp
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/vfs
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wear_levelling
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wifi_provisioning
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/wpa_supplicant
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/xtensa-debug-module
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp-face
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32-camera
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/fb_gfx
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/cores/esp32
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/variants/mhetesp32minikit
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/AsyncUDP/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/AzureIoT/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/BLE/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/BluetoothSerial/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/DNSServer/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/ESP32/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/FFat/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/HTTPClient/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/HTTPUpdate/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/NetBIOS/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/SD_MMC/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/SimpleBLE/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/Ticker/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src
  include: /home/pfeerick/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src
  include: /home/pfeerick/.platformio/packages/tool-unity
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/xtensa-esp32-elf
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/backward
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/lib/gcc/xtensa-esp32-elf/5.2.0/include
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/lib/gcc/xtensa-esp32-elf/5.2.0/include-fixed
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include
  include: /home/pfeerick/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/sysroot/usr/include

@pfeerick I changed the settings at C_Cpp.default.systemIncludePath so that it included the extra directories that manuelbl had pointed out. I don’t believe I added "${default}", as I didn’t think there were default values for the system include path that I wasn’t already including. I can reproduce if you believe that it’s worth looking into for the c/c++ extension team.

1 Like

Ok, reading the docs for that parameter, it says

If this setting has a value, then the system include path the extension gets from the compiler specified in the compilerPath setting will not be added to the path array that the extension uses for IntelliSense.

Which suggests this is the reason why the .platformio/packages/toolchain-xtensa32 paths were dropped… as it was no longer adding the include paths the compiler offered up… interesting… and quite nasty if you don’t realise it’s replacing part of the include path construction mechanic, not just allowing you to add it! :open_mouth:

1 Like