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

Default C/C++ configuration uses MSVC for IntelliSense rather than GCC #684

Closed
rhalkyard opened this issue Nov 4, 2018 · 2 comments
Closed

Comments

@rhalkyard
Copy link

rhalkyard commented Nov 4, 2018

The project that I am working on brings in the SPI.h header that is part of the standard Arduino distribution. This header uses the GCC-specific __attribute__() macro in several places, which causes IntelliSense to trip up and report nonsense errors in my project, since MSVC appears not to understand it.

If I modify c_cpp_properties.json to use the AVR-GCC compiler provided in the Arduino distribution, using the same command-line options that are used in the compilation process, and set intelliSenseMode to gcc-x64, I get much more sensible IntelliSense output. Since Arduino projects are always compiled using the Arduino AVR-GCC toolchain, and MSVC chokes on GCC-specific macros in official Arduino headers such as SPI.h, shouldn't this be the default value populated in c_cpp_properties.json for new projects, rather than MSVC?

The c_cpp_properties.json that I am using to make Intellisense work in my project (on a Mega2560 board) is as follows. Note that I have also modified the include paths; I can't remember what the reasoning behind them was, except for that I ran into issues with the default hardware\arduino\avr\** and tools\** paths at some point, and restricting the include paths to specific directories got things working again.

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:\\Program Files (x86)\\Arduino\\tools\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\bootloaders\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include"
            ],
            "forcedInclude": [
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
            ],
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "\"C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-g++.exe\" -Wall -Wextra -c -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
@kerrsmith
Copy link

kerrsmith commented Feb 2, 2019

I used the above code to get the vscode-arduino extension working so it shows intellisense and error highlighting. I have a detailed write up of what exactly I did to get it to work at the following location:

#765 (comment)

It is basically the code from above but I detail how to use the Arduino IDE to get the 'compilerPath' needed for different Arduino boards (such as the Nano).

Thanks for posting the above, I spent quite a while trying to figure out how to get errors and intellisense working with my Arduino code and this was the suggestion that finally got it all working.

@stale
Copy link

stale bot commented Apr 16, 2019

This issue has been automatically marked as stale and closed because it has not had recent activity. Please feel free to open a new issue if you would like further discussion. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2019
@dooriya dooriya closed this as completed May 9, 2019
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

4 participants