I'm trying to build C/C++ in Visual Studio Code. I installed C/C++ and all the relevant extensions.
#include <stdio.h>
int main() {
printf("Test C now\n");
return 0;
}
But there's a green line under #include <stdio.h>
saying "Add include path to settings". When I click it, it moves over to "c_cpp_properties.json".
How and where can I add include paths in the configurations below?
"configurations": [
{
"name": "Mac",
"includePath": ["/usr/include"]
}
]
This question is related to
c++
c
visual-studio-code
For Mac users who only have Command Line Tools instead of Xcode, check the /Library/Developer/CommandLineTools
directory, for example::
"configurations": [{
"name": "Mac",
"includePath": [
"/usr/local/include",
// others, e.g.: "/usr/local/opt/ncurses/include",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
"${workspaceFolder}/**"
]
}]
You probably need to adjust the path if you have different version of Command Line Tools installed.
Note: You can also open/generate the
c_cpp_properties.json
file via theC/Cpp: Edit Configurations
command from the Command Palette (??P).
This answer maybe late but I just happened to fix the issue. Here is my c_cpp_properties.json file:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/c++/5.4.0/",
"usr/local/include/",
"usr/include/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
I tried this and now working
Configuration for c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"compilerPath": "C:/MinGW/bin/g++.exe",
"includePath": [
"C:/MinGW/lib/gcc/mingw32/9.2.0/include/c++"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
task.json configuration
File
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]}
For everybody that falls off google, in here, this is the fix for VSCode 1.40 (2019):
Open the global settings.json: File > Preferences > Settings
Then select the tab 'User', open the section 'Extensions', click on 'C/C++'. Then scroll the right panel till you find a 'Edit in settings.json' button.
Last, you add the "C_Cpp.default.includePath" section. The code provided there is from my own system (Windows 7). You can use it as a base for your own libraries paths. (Remember to change the YOUR USERNAME
to your correct system (my case windows) username)
(edit info: There is a problem with the recursion of my approach. VSCode doesn't like multiple definitions for the same thing. I solved it with "C_Cpp.intelliSenseEngine": "Tag Parser"
)
the code before line 7, on the settings.json has nothing to do with arduino or includePath. You may not copy that...
JSON section to add to settings.json:
"C_Cpp.default.includePath": [
"C:/Program Files (x86)/Arduino/libraries/**",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino/**",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/avr/include/**",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/5.4.0/include/**",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/variants/standard/**",
"C:/Users/<YOUR USERNAME>/.platformio/packages/framework-arduinoavr/**",
"C:/Users/<YOUR USERNAME>/Documents/Arduino/libraries/**",
"{$workspaceFolder}/libraries/**",
"{$workspaceFolder}/**"
],
"C_Cpp.intelliSenseEngine": "Tag Parser"
My c_cpp_properties.json config-
{
"configurations": [
{
"name": "Win32",
"compilerPath": "C:/MinGW/bin/g++.exe",
"includePath": [
"C:/MinGW/lib/gcc/mingw32/9.2.0/include/c++"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
In your user settings add:
"C_Cpp.default.includePath":["path1","path2"]
I solved this issue by uninstalling Visual Studio that I had installed recently.
The best way to configure the standard headers for your project is by setting the compilerPath
property to the configurations in your c_cpp_properties.json
file. It is not recommended to add system include paths to the includePath
property.
Another option if you prefer not to use c_cpp_properties.json
is to set the C_Cpp.default.compilerPath
setting.
Source: Stackoverflow.com