0

I've recently switched to Visual Studio Code as IDE for a more complex Arduino project.

In order to avoid "cannot open source file" warnings related to #include statements for builtin Arduino libraries, I already added the Arduino directory to IntelliSence includePath setting.

Unfortunately, two external libraries do contain an #include for older Arduino versions:

#if ARDUINO >= 100
#include "Arduino.h"
#else
extern "C" {
#include "WConstants.h" // <-- this is the first
}
#endif

and

#if ARDUINO >= 100
#include <Arduino.h>
#else
#include "WProgram.h" // <-- this is the second
#include "pins_arduino.h" // <-- this one was found in Arduino dir
#endif

As this files is no longer part of the Arduino environment, I get a warning.

Question: How do I exclude this warnings regarding WConstants.h and WProgram.h from Visual Studio Code's IntelliSense without deactivating any other include warnings?

I am not sure whether this is related to Visual Studio Code include single file on excluded path .

Max
  • 61
  • 1
  • 7
  • Does [this](https://stackoverflow.com/questions/52234438/vs-code-giving-header-errors-for-arduino-missing-official-header) answer your question? – mmixLinus Feb 09 '22 at 10:13
  • Thank you for your reply. Unfortunately, it does not. The linked issue addresses only correct include paths, which I already did. The issue I have is that the mentioned libraries do not exist on my PC, as they are not included in recent Arduino IDE and included in the libraries for backwards compatibility, only. Hence, I'd like to ignore only those specific include warnings. – Max Feb 09 '22 at 16:52

1 Answers1

0

Thanks to a post in Arduino forum, I found a solution:

The Arduino IDE adds a macro with it's version. So adding ARDUINO=10813 in the vscode config renders the include of WProgram.h and WConstants.h inactive, hence no more include warnings.

Similar thing can be achieved for Serial library by adding USBCON.

So vscode config should look like:

{
    "configurations": [
        {

            ...

            "defines": [
                "USBCON",
                "ARDUINO=10813"
            ],

            ...

        }
    ],

}
Max
  • 61
  • 1
  • 7