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 }
Related
I just opened a folder (based on this setup) in VS Code (1.74) containing C code I would like to be handled by the CPPTools extension (1.13.8). Within the folder (.../rd-infra/arm-tf), there is an extensive amount of code in the tree. The default includePath for the folder/workspace includes "${workspaceFolder}/**". However, the second #include in the source (.../rd-infra/arm-tf/bl1/bl1_main.c):
#include <platform_def.h>
shows squiggles and an error:
cannot open source file "platform_def.h"C/C++(1696)
I tried right-clicking on the include to "Go to definition," but this failed.
Doing a search of the tree, I find about 74 versions of this file:
~/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf$ find . -name 'platform_def.h'
./plat/intel/soc/common/include/platform_def.h
./plat/st/stm32mp1/include/platform_def.h
./plat/hisilicon/poplar/include/platform_def.h
./plat/hisilicon/hikey960/include/platform_def.h
./plat/hisilicon/hikey/include/platform_def.h
./plat/mediatek/mt8186/include/platform_def.h
...
I thought this made the error all the more odd, as I would expect a redundancy issue with so many to choose from. That's not what the error says, but I went ahead and added the specific compiler to .../rd-infra/arm-tf/.vscode/c_cpp_properties.json to see if that helped:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
and nothing changed.
So, it appears to me that the ${workspaceFolder}/** is not being recursively searched.
Then I added the specific include directory for the version of the file that applies in my case:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/plat/arm/board/rdn2/include",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
And the squiggles disappeared. I right-clicked on the include to choose "Go to definition," which opened the platform_def.h header file, where there were includes with squiggles as well, showing the same error as before (1696).
So now I'm in the same boat with a new include line:
#include <lib/utils_def.h>
Searching for that file:
~/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf$ find . -name 'utils_def.h'
./include/lib/utils_def.h
So it looks like ${workspaceFolder}/** isn't even making it one level deep?
I also tried with the full path, both with and without using ${userHome}:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf/**"
],
"defines": [],
"compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
and it was back to unable to open platform_def.h (1696).
Am I misunderstanding the /** notation?
========= Edit 1 =========
Dumping predefined variables:
userHome: /home/rtillery
workspaceFolder: /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf
compiler path: /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
Verifying compiler path:
~/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf$ ll /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
-rwxr-xr-x 2 802 802 1213640 Feb 2 2022 /home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc*
And possibly related to #n.m.'s comment, I do get the following error (twice):
[12/20/2022, 10:47:36 AM] Unable to resolve configuration with compilerPath "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc". Using "/usr/bin/gcc" instead.
On the other hand, I don't actually see what the compiler output has to do with CPPTools recursively searching a path provided. (Adding compilerPath above was just a stab in the dark and probably muddied the waters around this question.) Maybe someone can explain if they are?
========= Edit 2 =========
Also, probably not related. In spite of the variable dump above (accomplished using the example at the bottom of this page), the editor shows a different expansion of the ${userHome} predefined variable, which includes the variable expansion and the variable name:
From c_cpp_properties.json:
"compilerPath": "${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
Error shown in the Problems tab, under the c_cpp_properties.json file:
Cannot find "/home/rtillery/Projects/ARMFVPs/FVP_RD_N2/rd-infra/arm-tf/${userHome}/Projects/ARMFVPs/FVP_RD_N2/rd-infra/tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc".
That's very strange.
Replacing the line with one based on the ${workspaceFolder} instead:
"compilerPath": "${workspaceFolder}/../tools/gcc/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc",
seems to work, as the error disappears.
========= Edit 3 =========
Filed a bug for the other issue mentioned above.
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.
I am working on Visual Studio Code on Windows 7 64-bit.
After searching online for quite a while, I still can't solve my problem: I have a C program that includes libusb.h. whenever I try to compile using gcc, I get the following error:
In file included from min.c:1:0:
min.h:8:20: fatal error: libusb.h: No such file or directory
#include <libusb.h>
^
compilation terminated.
I tried a few solutions online, changing c_cpp_properties.json and settings.json(causing to VSCode to not showing any error on the #include <libusb.h> line).
here is my files:
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
],
"browse": {
"path":[
"C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
]
},
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}
settings.json:
{
"C_Cpp.intelliSenseEngine": "Tag Parser",
"C_Cpp.commentContinuationPatterns": [
"/**",
"C:/Users/VAKNIN/Downloads/Orel-thesis/libusb-1.0.23/include/libusb-1.0"
]
}
I am pretty lost after hours on this problem, I would appreciate any help.
EDIT:
This the the complete output of the following command: gcc min.c -o min
where min.c is the only C file I have.
Find the location of your libusb, or if you don't have it get it from http://libusb.info/ and build it, or get a prebuilt package matching your system (win32 or win64).
Then make sure your compiler's search path includes the path of the include folder where libusb.h is, and the linker's search path includes the path where the library is.
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
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
}