arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.33k stars 396 forks source link

"Serial" is not recognized and is considered as an "Undeclared Identifier" #159

Open TheUnityGuru opened 3 years ago

TheUnityGuru commented 3 years ago

Describe the bug The class "Serial" is not recognized and is considered a "Undeclared Identifier"

To Reproduce Just try this to initialize the hardware serial in the void setup.

Expected behavior Well, nothing is supposed to happen. The IDE is supposed to recognize it

Screenshots image

Desktop (please complete the following information):

Additional context Just downloaded it, installed the arduino AVR boards, and tried out this simple sketch. NOTHING ELSE HAS BEEN DONE

matios13 commented 3 years ago

I have the same issue, Windows 10 , Arduino nano RP2040 connect , is there any walkaround ?

Wolfy7 commented 3 years ago

Same issue here. Windows 10 Pro 21H1 (19043.1165).

image

Version: 2.0.0-beta.10 Date: 2021-08-05T08:23:32.577Z CLI Version: 0.18.3 alpha [d710b642]

doronbehar commented 1 year ago

It seems that whenever a line such as:

extern Serial_ Serial;

is used in Arduino's code (USBAPI.h in this case), all methods inside Serial_ are not detected as belonging to the Serial class actually used in the users' sketches. I experience the same issue with the Keyboard.h external library. See:

https://github.com/arduino-libraries/Keyboard/blob/25ab3cdfd2d2cf93f2315fd4c13ef22c9622ba50/src/Keyboard.h#L146

Here's how I experience this with Neovim:

Screenshot from 2023-02-03 20-28-09|648x296

Lastaapps commented 9 months ago

If someone ends up here, a simple workaround is to define the USBCON macro, either at the beginning of main.h, or in your clangd config .clangd like this:

CompileFlags:
  Add: [
    -DARDUINO=186, # To prevent libs from using WProgram. (not needed here)
    -DUSBCON=,     # To prevent the Serial not being defined
  ]

Make sure this does not overwrite the normal macro value during the compilation process.