#include<avr/io.h> error c_cpp_properties.json automatic generation bug #1507
Description
VScode version: 1.67.2 (Universal) commit c3511e6
Arduino extension version: v0.4.12
To use port manipulation on PORTA I am explicitly including <avr/io.h>. I am getting an include error #include errors detected. Please update your includePath. Squiggles are disabled for this translation unit
on #include<avr/io.h>
.
This seems to be a pain point as there are a number of other users who reported this problem. I finally found a c_cpp_properties.json
configuration that fixes this problem:
{
"env": {
"arduino_path": "/Applications/Arduino.app/Contents/Java",
"arduino_avr_include_path": "${env:arduino_path}/hardware/arduino/avr",
"arduino_avr_include2_path": "${env:arduino_path}/hardware/tools/avr/avr/include",
"arduino_avr_compiler_path": "${env:arduino_path}/hardware/tools/avr/bin/avr-g++"
},
"configurations": [
{
"name": "Mac",
"defines": [
"ARDUINO=10810",
"__AVR_ATmega328P__",
"UBRRH"
],
"includePath": [
"${workspaceRoot}",
"${env:arduino_avr_include_path}/**",
"${env:arduino_avr_include2_path}/**"
],
"forcedInclude": [
"/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h"
],
"intelliSenseMode": "gcc-x64",
"cStandard": "c11",
"cppStandard": "c++11",
"compilerPath": "${env:arduino_compiler_path} -std=gnu++11 -mmcu=atmega328p"
}
],
"version": 4
}
but every time, it kept getting overwritten by the Arduino extension and the automatically generated c_cpp_properties.json does not work. I discovered from #438 that this is now a feature since 0.4.0. However, the c_cpp_properties.json generation logic seems buggy from my struggle with this #include error.
(outdated, see edit below) The current workaround is to disable the IntelliSense auto generation and use the above c_cpp_properties.json. For anyone else having this issue here's a screen shot of the setting:
It would be great to see the automatic generation work though.
EDIT: I found a better workaround from #1279 that I'll include here for posterity...
You can have c_cpp_properties.json
generated automatically initially by searching and running Arduino: Rebuild IntelliSense Configuration
in View->Command Palette
or cmd+shift+p
for mac. After this, check .vscode/arduino.json
to ensure a configuration with name Arduino
has been generated and also make sure C/C++. .vscode/c_cpp_properties.json
should look something like the snippet below. If you don't get this make sure you don't have Arduino: Disable Intelli Sense Auto gen
checked/disabled in the extension settings.
{
"version": 4,
"configurations": [
{
"name": "Mac",
"compilerPath": "/usr/bin/clang",
...
},
{
"name": "Arduino",
...
}
Make sure you use the configuration we just generated by searching and running C/C++: Select a Configuration...
in command palette as above or alternatively clicking on the bottom bar as shown in this screenshot
At this point, most of your intellisense errors should be fixed but if you're using any IO port definitions you'll still get an error. To fix this, add a line to defines
referencing your specific board under the Arduino C++ configuration. As of writing this edit, I am using an ATTiny85 and the definition is "__AVR_ATtiny85__"
. You can find a list of these defines at <avr/io.h>. So your .vscode/c_cpp_properties.json
should look something like this:
{
"version": 4,
"configurations": [
{
"name": "Mac",
"compilerPath": "/usr/bin/clang",
...
},
{
"name": "Arduino",
...
"defines": [
"__AVR_ATtiny85__", <---- or your board's define
"F_CPU=1000000L",
"ARDUINO=10819",
"ARDUINO_attiny",
...
],
...
}
Lastly, add "intelliSenseGen": "disable"
to .vscode/arduino.json
to prevent your changes from being overwritten. Note that you need to set this to true if you need to update the generated c_cpp_properties.json
configuration in the future.
Your intellisense should now work!