Arduino extension for vscode - Syntax highlighting not working - visual-studio-code

i am trying to use vscode and the arduino-cli. The extension is working correctly in veryfing and uploading the code to the board but it keeps highlighting arduino keywords (e.g.: digitalWrite) as errors, and as far as i can tell this should not happen.
I am going to attach the arduino.json, c_cpp_properties.json files in because i read that the problem may lay here.
arduino.json:
{
"sketch": "first.ino",
"configuration": "cpu=atmega2560",
"board": "arduino:avr:mega",
"port": "COM5"
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c89",
"cppStandard": "c++98",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}

Have you tried adding the paths of all libraries your Arduino IDE program comes with? Notice the line with the forcedInclude instruction that points to the path of the Arduino.h file.
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/EEPROM/src",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/HID/src",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SoftwareSerial/src",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/SPI/src",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/libraries/Wire/src"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"ARDUINO_AVR_UNO",
"ARDUINO_ARCH_AVR"
],
"compilerPath": "C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc.exe",
"forcedInclude": [
"C:/Program Files (x86)/Arduion/hardware/arduino/avr/cores/arduino/Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

Related

Setting up vscode with msys2 clang

I was trying to switch my Vscode from msys2 gcc to msys2 clang. I have downloaded clang according to the msys2 documentation provided. I have also followed the visual studio documentation for setting up clang. But my visual code fails to recognize iostream header.
I updated my environment path:
I also updated required include paths in my vs code configuration files:
cpp_properties:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"C:/msys64/clang64/include",
"C:/msys64/clang64/include/**",
"C:/msys64/clang64",
"C:/msys64/clang64/include/c++/v1",
"C:/msys64/clang64/lib/clang/14.0.4/include",
"C:/msys64/clang64/lib/clang/14.0.4/include/**",
"${workspaceFolder}/**",
"C:/msys64/clang64/bin",
"C:/msys64"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/msys64/clang64/bin/clang++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"C:/msys64/clang64/include",
"C:/msys64/clang64/include/**",
"C:/msys64/clang64/include/c++/v1",
"C:/msys64/clang64/lib/clang/14.0.4/include",
"C:/msys64/clang64/lib/clang/14.0.4/include/**",
"${workspaceRoot}",
"C:/msys64/clang64/bin",
"C:/msys64"
],"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Still i keep getting the following error:

it is showing that 'gcc not found' on vs code even though mingwx64 is installed and is in system path variables

i have mingwx64 installed on my device and is in the path variables as well
i can run it in terminal and powershell and pretty much everywhere but still in vs code it is showing my an error like this.the error message
also the c_cpp_properties.json file screenshot
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": []
}
],
"version": 4
}
please help...

How to fix Linux paths created by CMake Tools in ".vscode\c_cpp_properties.json" in VSCode?

I am preparing to develop a cross-platform project with CMake and so I used Cmake Tools and it created following compilerPaths:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c18",
"cppStandard": "c++20",
"intelliSenseMode": "clang-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerArgs": [],
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
"cStandard": "c18",
"cppStandard": "c++20",
"intelliSenseMode": "msvc-x64",
"compilerArgs": [],
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
In PROBLEMS tab I see Cannot find "\usr\bin\gcc". and that's obvious, because I am on Windows, but
the name values Linux and Win32 have some special meanings and
the paths have not been generated by me, but automatically so
I would expect the "PROBLEM" should not be there.
So how to correctly fix the "PROBLEM"?
You just need to switch the config.
On the bottom right it should say Linux (the name of the config).
Click on Linux and switch to Win32.
I got the same error on Windows when my config was set to Linux. When switching to the Win32 config I get no error.

How could I see the content of the Predefined variable in Visual Studio Code

For example:
{
"name": "MinGW",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"includePath": [
"${workspaceFolder}"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17"
}
I want to know what ${workspaceFolder} exactly is in this situation.
Is there a way to print it's content in the terminal or in a file?

ADD .lib file in visual studio code c++

I need to include jsoncpp in my visual studio code.
Is there any way to include .lib file in visual studio code?
this is my
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/*",
"${workspaceFolder}/C++Script/Dependencies/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.16299.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
I included json.h( although my compiler says it can't find the header file ) and I would like to include .lib file as well.
Can you tell me how to do that? I do know how to do this in visual studio. ( with liker )
c_cpp_properties.json is for Intellisense, you need to use tasks.json. Example:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I",
"C:\\vcpkg\\installed\\x86-windows\\include"
],
...
}