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.
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.
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
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 }
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
}