VS Code Incude Headerfile - c

I know this question was answered often on this plattform but the suggestions didn't work. I want to include #include <sys/mman.h> to my C-file. This does not work because the settings of include Path are not changed. I followed the common suggestion of going to the json c_cpp_properties.json file and include the path by myself
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\msys64\\mingw64\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
But the c-file where I want to add #include <sys/mman.h> still says that I should change the include Path settings.

Related

VS Code IntelliSense c_cpp_properties.json Include Path not working

I am trying to make C IntelliSense functional. Tired of the red squiggly line underneath the statement #include <fftw3.h> in any of my .c files, I added the following configuration to the c_cpp_properties.json file within VS Code:
"includePath": [
"${workspaceFolder}/**",
"~/../../opt/homebrew/Cellar/**"
For reference, I would compile my files with the following command:
gcc test.c -I/opt/homebrew/Cellar/fftw/3.3.10_1/include -L/opt/homebrew/Cellar/fftw/3.3.10_1/lib -lfftw3. My working directory is going to be /Users/jacobivanov/Desktop/College/CFDG. Shouldn't this be working, and if not, why?
#topher217, the following is my C/C++ Log Diagnostics Output:
-------- Diagnostics - 2/13/2023, 11:34:17 AM
Version: 1.13.9
Current Configuration:
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/Cellar/fftw/3.3.10_1/include"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64",
"configurationProvider": "ms-vscode.makefile-tools",
"mergeConfigurations": true,
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"browse": {
"path": [
"${workspaceFolder}/**",
"/opt/homebrew/Cellar/fftw/3.3.10_1/include"
],
"limitSymbolsToIncludedHeaders": true
}
}
Custom browse configuration:
{
"browsePath": [
"/Users/jacobivanov/Desktop/University of Connecticut/Computational Fluid Dynamics Group/1D FFTW Approximation",
"/opt/homebrew/Cellar/fftw/3.3.10_1/include"
],
"compilerPath": "/usr/bin/gcc",
"windowsSdkVersion": "",
"compilerArgsLegacy": [
"-o",
"FFTW"
]
}
Translation Unit Mappings:
[ /Users/jacobivanov/Desktop/University of Connecticut/Computational Fluid Dynamics Group/1D FFTW Approximation/approx_1D.c ]:
/Users/jacobivanov/Desktop/University of Connecticut/Computational Fluid Dynamics Group/1D FFTW Approximation/approx_1D.c
Translation Unit Configurations:
[ /Users/jacobivanov/Desktop/University of Connecticut/Computational Fluid Dynamics Group/1D FFTW Approximation/approx_1D.c ]:
Process ID: 96358
Memory Usage: 50 MB
Compiler Path: /usr/bin/gcc
Includes:
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX13.0.sdk/usr/include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include
/Library/Developer/CommandLineTools/SDKs/MacOSX13.0.sdk/usr/include
/Library/Developer/CommandLineTools/usr/include
Frameworks:
/Library/Developer/CommandLineTools/SDKs/MacOSX13.0.sdk/System/Library/Frameworks
Standard Version: c17
IntelliSense Mode: macos-clang-arm64
Other Flags:
--clang
--clang_version=110000
Total Memory Usage: 50 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 2649
Number of files parsed: 1053
Other suggestions:
My C/C++ extension was not requiring a restart or reinstall. Both were tried.
Reset/Restart IntelliSense did not work. Both were tried.
My new error is cannot open source file "fftw3.h"C/C++(1696)
#Patryk GawroĊ„ski, unfortunately, I need to use Makefile for other reasons.

how to write "include path(folder that contain header)" for IntelliSense Configurations in VS Code

the directory of the header is C:\MinGW\include\stdio.h. How can I convert it to the path
To do this in VS Code, first use the command Ctrl + Shift + P to pull up the Command Pallette. Then, type in the command C/C++: Edit Configurations (UI). This will pull up a json file in which you can include paths to header files to be included for IntelliSense. The json should look something like this:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
To add a custom path, according to the json reference, you can specify another path under the "includePath property. Here is what you should change this json property to, according to your custom header's location:
"includePath": [
"${workspaceFolder}/**",
"C:/MinGW/include/"
],
Note that I did not include the actual header file, as the path must point to a folder that contains the header file rather than to the header itself. Also notice that you must use forward slashes rather than back slashes.

C\C++ in VS Code with Linux Subsystem For Windows

I am having issues getting my "includes" to work in my editor in VS Code on Windows 10 build 17134 using Linux Subsystem for Windows. I have the C/C++ extension installed and can run my application using the launch.json information outlined in the documentation here.
In their documentation here, Microsoft outlines how to set up a c_cpp_properties.json to get around this issue, but it has not advanced me much. Currently, I am getting an error under my "includes" line which says:
#include errors detected. Please update your includePath. IntelliSense features for this translation unit (C:\Users\Username\Source\c-lang\hello.c) will be provided by the Tag Parser.
cannot open source file "stdio.h"
My c_cpp_properties.json:
{
"configurations": [
{
"name": "WSL",
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${workspaceFolder}",
"/usr/include/"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}",
"/usr/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
Figured it out thanks to this comment on a Github issue.
I took the command they recommended and edited it to use C and not C++ and ran it in WSL:
gcc -v -E -x c -
It listed where all gcc was looking for C libs, among other things. I copied that list and put the individual paths in the "includePath" and "path" arrays. Here is my updated c_cpp_properties.json file:
{
"configurations": [
{
"name": "WSL",
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${workspaceFolder}",
"/usr/include/x86_64-linux-gnu/5/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu/5/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}",
"/usr/include/x86_64-linux-gnu/5/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu/5/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
Hope this helps someone.
I am new to C++ but the way I fixed this issue was to find all of my possible include paths by searching for stddef.h on my machine and then adding these to my includePath in VS code. These are the paths that were added:
C:\Cygwin\lib\gcc\x86_64-pc-cygwin\9.3.0\include
C:\Cygwin\lib\gcc\i686-w64-mingw32\9.2.0\include
C:\Cygwin\lib\gcc\x86_64-w64-mingw32\9.2.0\include
C:\Cygwin\usr\i686-w64-mingw32\sys-root\mingw\include
C:\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include
C:\Cygwin\usr\include\c++\v1
C:\Cygwin\lib\gcc\i686-pc-cygwin\6.4.0\include
C:\Cygwin\lib\gcc\i586-pc-msdosdjgpp\5.4.0\include
C:\Cygwin\lib\gcc\i586-pc-msdosdjgpp\5.4.0\include-fixed
C:\Cygwin\usr\i586-pc-msdosdjgpp\sys-include
C:\Cygwin\lib\clang\8.0.1\include
C:\Cygwin\lib\clang\8.0.1\include

VS code: include file not found in browse. path.?

IN VS CODE i get the error "include file not found in browse. path."
with an error squiggle under my header file #include <stdio.h>
how can i make this library accessible to my code.
all i have is a folder and a main.c file
Very new to all this, the other answers seem to be out of my depth as im not sure what files they're accessing.
Thank you in advance.
Very similar problem to the one posed here, and thankfully a very similar solution.
Ctrl-Shift-P will open the "command bar", start trying C/Cpp: Edit Configurations until it's the top result then hit enter, this will create a c_cpp_properties.json file in the .vscode folder of your current project directory (making this configuration unique to this project, so you'll need to repeat this for other projects). This json file has sections for Mac, Linux and Win32, edit the section relevant to you or all if you know the paths for the other platforms. Each block has a name, includePath, defines, intelliSenseMode and browse property. The browse property has a child array called path (which is what we're looking for, include file not found in *browse.path*), add the paths to your include directories here, one string each, and remember to use forward slashes even if Windows gives you them as backward slashes.
While the offending error disappeared when adding the correct path to browse.path, I also added it to the includePath section because according to the hover tooltip includePath is used by the intellisense engine whereas browse.path is used by the tag parser. Can't hurt to have both set up correctly.
Attaching example of .vscode\c_cpp_properties.json file with browse.path which solved my issues with Arduino dependencies
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTProtocol_MQTT\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTUtility\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTHub\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\WiFiManager\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\ArduinoJson\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.2\\**",""
],
"forcedInclude": [],
"browse": {
"path":[
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTProtocol_MQTT\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTUtility\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTHub\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\WiFiManager\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\ArduinoJson\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.2\\**"]
},
"intelliSenseMode": "msvc-x64",
"compilerPath": "C:\\WinAVR-20100110\\bin\\avr-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
All you need to have is, to check if browse.path exists in the c_cpp_properties.json file. If not include this part. It should fix the issue.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4 }

Visual Studio Code include file not found in include directory (Windows 10)

I am trying to get intellisense in Visual Studio Code. I downloaded the the C/C++ extension from the marketplace: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools and also installed MinGW with the packages mingw32-base and mingw32-gcc-c++. I added the MinGW bin folder to Path in my Environment variables.
When I add any include statement in my .c file, such as #include <stdio.h>, Visual Studio Code says:
Include file not found in include directory
Am I not configuring correctly? How can I get intellisense for C/C++?
First, make sure to create a c_cpp_properties.json file in your .vscode folder
Hint: Use the Command Palette (Ctrl+Shift+P) and type C/Cpp: Edit Configurations
Add include paths like this:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"path_to_your/MinGW/lib/gcc/mingw32/4.8.1/include/c++"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
]
}
As an expansion to wbmrcb's answer, I found header files under Windows Kits directory:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt
On Fedora linux I added the following path where all my c header files lives.
/usr/include/**
to myc_cpp_properties.json file.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**"
],
...
}
],
"version": 4
}
I am using MinGW 8.1.0 and the C/C++ extension from microsoft, this worked for me -
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++",
"C:/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/tr1",
"C:/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/i686-w64-mingw32"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw32/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}

Resources