VSCode, PlatformIO, Arduino, and includePath

I’m running into a small collection of issues that I can’t seem to nail down, using VSCode, PlatformIO, and the Arduino framework:

For reference, my platformio.ini file:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps=
    TimerOne
    FastLED
build_flags = 
    -I"C:/Users/<MyUsername>/.platformio/packages/toolchain-atmelavr/avr/include"

First, VSCode seems unhappy about any #include <Arduino.h> because it complains about cannot open source file "avr/pgmspace.h" (dependency of "Arduino.h"). I’ve explicitly added the framework to the .ini file, I don’t know what else I’m missing to get Intellisense to correctly include the avr headers.

I’ve found I can resolve this first issue by adding the directory in my build_flags directly to the c_cpp_properties.json file, but of course PlatformIO overwrites this all the time. However for the life of me I can’t figure out how to get the build_flags in platformio.ini to actually add this directory. I’ve tried quotes, no quotes, forward slash, backward slash… What am I missing?

Edit: tl;dr View the linked thread, revert to an earlier version of the C/C++ extension.

Have you tried building some code yet? As it’s possible the full toolchain is not installed yet, hence the ‘error’ from IntelliSense. It’s also possible you’re facing a similar problem that others have recently raised, with IntelliSense not behaving properly in the last couple of revisions… Thanks Microsoft! The last two or three posts show how to stop extension auto-updates, and then revert to an older version of intellisense… 0.26.0 seems to be working better for some - doesn’t seem to bother my system, but who knows, mine will probably break tomorrow now that I said that!

Anyway, whilst it’s annoyance, if the code compiles, it is just that for now, an annoyance.

I have a remaining question: How would I add a path to the c_cpp_properties.json file with PlatformIO? Most of the answers related to that just say “use build_flags”, but with my build_flags above, the directory doesn’t get added to includePath in c_cpp_properties.json.

That said, rolling back to 0.26.0 resolved the first issue (thanks!), so there’s no longer a need to explicitly add the AVR headers, but I’d still like to know how to add paths in case something similar comes up in the future.

1 Like

Sorry, didn’t mention anything about that as you’d done it correctly.

Having said that, it seems if you go any deeper than .platformio/packages/toolchain-atmelavr with a -I build_flag seems it gets rejected / ignored. Perhaps it’s not allowed because it’s a internal folder so should be included automatically by the compiler, or perhaps it’s a bug.

Edit: Sorry, I had `/avr at the end of the path, which was wrong. So we got the same result.

Huh, you’re right, though for me I can’t actually go beyond C:/Users/<Username>/.platformio/packages/toolchain-atmelavr before it doesn’t work. I might have a longer username / base path though, or perhaps it’s being ignored intentionally because it’s “already included” as you suggest.

Good to know at least for the future; thanks again.

1 Like