Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

#include<avr/io.h> error c_cpp_properties.json automatic generation bug #1507

Open
0xAl3xH opened this issue May 25, 2022 · 5 comments
Open

Comments

@0xAl3xH
Copy link

0xAl3xH commented May 25, 2022

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:
Screen Shot 2022-05-24 at 5 10 03 PM

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
Screen Shot 2022-11-21 at 10 29 13 AM

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!

@github-actions github-actions bot added the triage New issues that have not been reviewed. label May 25, 2022
@benmcmorran
Copy link
Member

Thanks for the report and workaround @al3x-huang! I'm having trouble reproducing this issue. Can you provide some extra information?

  • What operating system are you using? (I assume Mac from the configuration file)
  • What Arduino device are you using? (Looks like maybe the Mega 2560, but I wanted to double check)
  • Is the extension connected to the Arduino IDE or arduino-cli?

@benmcmorran benmcmorran added intellisense needs-more-info More details about this issue are needed for it to be actionable. and removed triage New issues that have not been reviewed. labels Jun 6, 2022
@drzony
Copy link

drzony commented Jun 10, 2022

I'm having a similar issue. It seems that the chip define is missing from the defines, in my case adding __AVR_ATtiny2313__ to defines helps to solve the problem.
Running on Windows, using Arduino IDE with ATTiny2313.
echo "" | avr-g++ -mmcu=attiny2313a -dM -E -x c++ - has this defined

@drzony
Copy link

drzony commented Jun 10, 2022

After digging deeper it seems that cocopa does not pass -mmcu flag when requesting built-ins https://github.com/elektronikworkshop/cocopa/blob/ce125785574735b777e2a40bad0e85dd41580692/src/BuiltInInfoParserGcc.ts#L24

@BelKed
Copy link
Contributor

BelKed commented Jun 11, 2022

I'm having a similar issue. It seems that the chip define is missing from the defines, in my case adding __AVR_ATtiny2313__ to defines helps to solve the problem.

I think it has to do with this issue:

@drzony
Copy link

drzony commented Jun 11, 2022

Yes, that's the same root cause

@gcampbell-msft gcampbell-msft removed the needs-more-info More details about this issue are needed for it to be actionable. label Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants