microsoft / vscode-arduino

Visual Studio Code extension for Arduino
Other
1.16k stars 218 forks source link

Include files not found when in VSCode but fine when in ArduinoIDE #1614

Open reflectingme opened 1 year ago

reflectingme commented 1 year ago

When I create a file within the ArduinoIDE2 everything runs fine, all the #includes are found and the file compiles and uploads to my LilyGo T-Display Touch board perfectly. However, when I open the very same file in VSCode, I get a multitude of cannot find source file errors.

Why would the code run perfectly in ArduinoIDE yet the very same file won't compile in VSCode. Any pointers please? Why would the include paths be any different?

Top part of screenshot is file in VSCode, bottom part is in Arduino.

Screenshot 2023-03-04 at 21 22 12
MickGyver commented 1 year ago

It seems that on Windows, libraries must be in the C:\Users\[user]\Documents\Arduino\libraries folder, then they will be found by the compiler, the only way I'm able to compile is if I copy my libraries to the folder I mentioned above. (I mentioned this find in another issue also)

MickGyver commented 1 year ago

From some more testing, I guess that the arduino-cli tool when used by VS Code doesn't use the configuration file (arduino-cli.yaml) that is stored in the folder %userprofile%.arduinoIDE by the Arduino IDE 2.0. I copied arduino-cli.yaml from %userprofile%.arduinoIDE\ to %userprofile%\AppData\Local\Arduino15\ and compilation now works.

reflectingme commented 1 year ago

Thanks for this info, Mick. I've been a bit unwell the last few days so haven't looked into this more but starting to feel better now so will look tomorrow. I should also have mentioned in my original post that I am using VSCode on a Mac and not the Windows version, apologies.

AJ-Work-Smoothie commented 1 year ago

From some more testing, I guess that the arduino-cli tool when used by VS Code doesn't use the configuration file (arduino-cli.yaml) that is stored in the folder %userprofile%.arduinoIDE by the Arduino IDE 2.0. I copied arduino-cli.yaml from %userprofile%.arduinoIDE\ to %userprofile%\AppData\Local\Arduino15\ and compilation now works.

YOU ARE A BEAST! This is the only thing that I found has worked so far. Can you please share it other place? Apparently this is quite the unsolved problem.

livingcreative commented 10 months ago

Awesome. Moving yaml config helped.

waqasahmad531 commented 10 months ago

The solution that worked for me was to open the the C:\Users\\AppData\Local\Arduino15\arduino-cli.yaml file and update the user directory to the installation path of arduino which in my case was: C:\Program Files (x86)\Arduino

vlrmprjct commented 3 months ago

You can also paste the arduino-cli.yaml file into the root directory of your project when using VSCode instead of copying this file into your %user% directory.

project.root
    /arduino-cli.yaml
    /.vscode
    /whatever
    /src
        /code
            /code.ino

It should work.