Configure VSCode include path - visual-studio-code

I use VSCode to edit Xilinx SDK files. The VSCode issues "problems" that include path can't be found.
I used the bulb "show fixes":
Add to "includePath": D:/Other/Xilinx/SDK/2017.4/gnu/aarch32/nt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/6.2.1/include
But VSCode is still complaining about the missing include path, although each Add to "includePath" adds a correct path to "c_cpp_properties.json" in the projects .vscode folder.
What's wrong with the include configuration?
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/standalone_bsp_0/ps7_cortexa9_0/include",
"D:/Other/Xilinx/SDK/2017.4/gnu/aarch32/nt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/6.2.1/include",
"D:/Other/Xilinx/SDK/2017.4/gnu/aarch32/nt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/6.2.1/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
That's the line complained by VSCode:
#include <stdint.h>
Edit:
Each accepting of the "fix" causes an additional line with the same path in "includePath", but this doesn't solve the problem. So what you see in the c_cpp_properties.json dump is caused by the "fix".

Your c_cpp_properties.json appears to have the same problems as in another answer I recently posted. To summarize:
Add compilerPath.
Change intelliSenseMode to gcc-x86 or gcc-x64. (Not sure which, there is no gcc-arm option.)
Check out the tutorial.
Try running "C/C++: Log Diagnostics" and "gcc -v -E -dD".
See the linked answer for a few more hints and details.

Related

How to build a project with CMake and MinGW using Visual Studio Code?

I found an instruction on how to use VS Code with MinGW, but can't figure out how to use it with my project that have CMakeLists.txt.
Should I use a plugin like CMake Tools in addition to C/C++ extension used in the instruction?
E. g. assume I did all the steps and was able to compile hello.cpp with a configuration like this:
{
"configurations": [
{
"name": "GCC",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
How to build my CMakeLists.txt then?
EDIT1:
Configuration provider
We can get some configuration information from ms-vscode.cmake-tools:

Visual Studio Code IntelliSense for Arduino and DxCore

Has anyone here gotten IntelliSense to work relatively flawlessly in Visual Studio Code for Arduino with DxCore projects? I've gotten most of the way, but still have some issues.
For me, any calls to Serial.printf() get marked with a red squiggly. Ctrl+clicking on printf shows me the definition just fine. Other things here and there have the same behavior. For example, va_start within the printf definition.
In addition to that, when verifying the sketch, I get:
[Error] Failed to read or write IntelliSense configuration: {}
Don't think it's a real problem, but it's annoying.
Here's my c_pp_properties.json file:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Users\\nabel\\OneDrive\\Documents\\ArduinoData\\packages\\DxCore\\hardware\\megaavr\\**",
"C:\\Users\\nabel\\OneDrive\\Documents\\Arduino\\libraries\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\libraries\\**"
],
"forcedInclude": [
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"ARDUINO=10816", // Should be updated for version of Arduino IDE installed; https://stackoverflow.com/a/30928558
"USBCON"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
If anyone has IntelliSense working well, could you share your c_pp_properties.json file? Thanks!
JSON doesn't allow javascript comments my friend! Remove it and Bob's your uncle.

How do I fix a "could not be parsed" Visual Studio Code configuration error?

I am currently setting up Visual Studio Code for C++ usage, however when setting up my compiler path in edit configuration (UI) to C:\MinGW65\mingw64\bin\g++.exe it shows up with the error :
[27/04/2021, 10:25:03 pm] "C:\MinGW64\mingw64\bin\g++.exe" could not be parsed. 'includePath' from c_cpp_properties.json in folder 'Start' will be used instead.
Note: Start is the name of current opened directory.
I have tried setting up my compiler path to: C:/MinGW64/mingw64/bin/gcc.exe, which shows up with no errors however gcc.exe as researched is a compiler that compiles mainly C.
When looking inside the visual studio code documentations and the tutorial videos, it stated to write the path to the compiler nothing more nothing less, which I have done above. I have tried to solve this error; resulted in nothing. How could I fix this error?
Error:
[27/04/2021, 10:39:24 pm] "C:\MinGW64\mingw64\bin\g++.exe" could not be parsed. 'includePath' from c_cpp_properties.json in folder 'Start' will be used instead.`
Configuration File:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/MinGW64/mingw64/bin/g++.exe",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}

How does the C/C++ extension of Visual Studio Code find the default compiler?

I started a project and I created my c_cpp_properties.json file. I was quite surprised to find that the contents of the file showed a compiler by default:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "",
"compilerPath": "C:\\DiaSemi\\SmartSnippetsStudio\\Tools\\mingw64_targeting32\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
I was wondering how did it find that particular gcc.exe path, as even though it's installed in my computer, I've never used it, and if I had, I would have done it from the Dialog Semi IDE, not Visual Studio Code and if I had ever set a default compiler, that's probably the last one I would have chosen. I checked the settings, and for the life of me, I can't find any "default compiler" setting.
VS Code found it through a very odd include in my general path in Windows. After deleting it, new projects don't have a default compiler path.

How to use the Visual Studio Code to navigate Linux kernel source

I am converting from Eclipse CDT. The preprocessor macro feature is a must when navigating through C/C++ code with preprocessor defines (whether explicitly specified in Makefile or included through an external auto-generated header file). Without this, navigating the Linux source would be impossible, as described on this seminal wiki page on using Eclipse to study the Linux code. I am looking for an equivalent feature for Visual Studio Code. Would appreciate a pointer.
Install ms-vscode.cpptools extension.
Open kernel source folder in VSCode.
Follow the instructions, add "${workspaceFolder}/include" and "${workspaceFolder}/arch/{your arch}/include" to includePath, "your arch" is x86/arm etc.
Wait for IntelliSence indexing.
As of today I have found the use of the vscode-linux-kernel project to be superior to both answers listed above, as navigation through the code and Intellisense works very well.
The project is released to the public domain.
This is what worked best for me (fixing some issue of the snippet in a previous answer):
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include",
"${workspaceFolder}/arch/<arch>/include",
"${workspaceFolder}/arch/<arch>/include/generated"
],
"forcedInclude": [
"${workspaceFolder}/BUILD/include/generated/autoconf.h"
],
"defines": [
"__KERNEL__"
],
"compilerPath": "/usr/bin/gg", # replace this with your compiler (also gcc cross-compiler)
"cStandard": "c11",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Where you may replace <arch> with your actual architecture.
I did't need to add the arch folder (for x86_64 it was actually empty), but add some basic defines to make compiler specific types and macros visible to intellisense. My minimal config is shown below. For perfect results you would have to add all defines as configured in your kernel .config file (e.g. CONFIG_MMU). There are many of those, so typically you will only focus on the few you really care about.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [
"__GNUC__",
"__KERNEL__"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Makefile Tool provides IntelliSense configurations to the VS Code C/C++ Extension for Makefile projects. We dont have to manage the c_cpp_properties.json manually.
It's the best solution I'm aware of to work with the Linux kernel code in VSCode.
These responses are helpful, but https://www.kernel.org/doc/html/latest/process/programming-language.html would indicate that cStandard should be gnu89.
In my case, none of the above answers really solved the problem. Here is my solution.
Disable or uninstall the official C/C++ plugin.
Install the clangd plugin.
Build the kernel with clang:
/path/to/kernel_source$ make CC=clang defconfig
/path/to/kernel_source$ make CC=clang -j16
Generate the compile_commands.json:
/path/to/kernel_source$ python ./scripts/clang-tools/gen_compile_commands.py
If no error occures, you will find compile_commands.json in /path/to/kernel_source/.
Configure the clangd plugin with the following parameters:
Open any C file in kernel source and enjoy it :)