This questions might look similar to other questions but nothing I've tried has worked. I'm using a library called PROS for Vex robotics. I get the include detected error where it can't find the main.h file located in the workspace folder. I checked the c_cpp_properties.json to check if the folder was somehow not included.
Additionally, I tried re-installing VS code, updating the PROS library, making a new project. Nothing seems to be working, maybe I'm just overlooking a simple problem.
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/Users/cjm10000/Desktop/7701X/7701x_code/include"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"browse": {
"path": [
"${workspaceFolder}/**"
]
}
}
],
"version": 4
}
Here's the folder structure and error output:
Related
I am using vs code on macOs and I have this error.
I searched all the solution. It points me to configure the include path.
I tried to use below code in the terminal
clang++ -v -xc++ -
to get where the include search start.And I got this information.
So I include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include into the configuration json like below.
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
But vscode tells me that it cannot find this path. Is there anything that I did wrong? How can I fix the includePath error on macOS?
So, whenever I create a new folder in vs code, the default compiler comes out to be gcc-11 but I want it to be clang.
c_cpp_properites.json file when I am trying to create a cpp file in a new folder:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intellisenseMode": "macos-gcc-x64"
}
],
"version": 4
}
I have to replace my .json file code over and over again with the given code.
new c_cpp_properties.json file:
{
"configurations": [
"name": "Mac",
"includePath": [
"/usr/local/include",
"/usr/local/Cellar/gcc/11.2.0_3/include/c++/11",
"${workspaceFolder}/**",
"/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/x86_64-apple-darwin21"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/clang++",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intellisenseMode": "macos-clang-x64"
],
"version": 4
}
So I want that whenever I create a new folder the vs code's default c_cpp_properties should be the second one, not the first one. Can anyone help me out to do so?
I'm getting squiggly lines under the statements of #include "rclcpp/rclcpp.hpp" from the ROS2 tutorial I'm going through and updating IncludePath in c_cpp_properties.json is not fixing the issue.
Here's what my c_cpp_properties file looks like:
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/ros/foxy/include/**",
"/home/thomas/ws_ros2/src/cpp_pubsub/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++14",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
The ROS extension recognizes that I'm working with a ROS package so my settings.json looks like this:
{
"python.autoComplete.extraPaths": [
"/home/thomas/ws_ros2/install/warehouse_ros_mongo/lib/python3.8/site-packages",
"/home/thomas/ws_ros2/install/moveit_msgs/lib/python3.8/site-packages",
"/opt/ros/foxy/lib/python3.8/site-packages"
],
"C_Cpp.errorSquiggles": "Enabled"
}
But no matter what I do I can't seem to get rid of these squiggles.
Removing configurationProvider from c_cpp_properties.json did the trick and intellisense is working now.
VS Code on my Mac yields #include errors for header files and third-party libraries (wxWidgets in this case). I read everything I could find, adjusted "includePath" settings in "c_cpp_properties.json", but nothing helps.
Header files are located in the same folder as .cpp files ("/src/"). The project builds and runs nicely, but VS Code yields #include errors and error squiggles cover my entire project.
Below is the screenshot and a JSON file with VS Code settings.
#include error screenshot
c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/**",
"/usr/local/Cellar/wxmac/3.0.5.1/include/wx-3.0"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
Please help me straighten this out.
————— UPDATE —————
I was recommended to use the following settings in c_cpp_properties.json:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${vcpkgRoot}/x64-osx/include",
"/usr/local/Cellar/wxmac/3.0.5/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
Header file #include errors are gone, but the third-party library ("WX") errors persist. In the JSON above, there is the line "${vcpkgRoot}/x64-osx/include" written in the "includePath".
This is the vcpkg package which helps install third-party libraries easily.
After installing vcpkg, I installed wxWidgets via vcpkg, but the library isn't linking in VS Code (builds just fine though) and I get error squiggles as shown on the screenshot below:
Could you please explain how to straighten it out?
On the includePath property add ** to the end of your directories path:
...
"includePath": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/**",
"/usr/local/Cellar/wxmac/3.0.5.1/include/wx-3.0/**"
],
You can look form more details about c_cpp_properties.json on the documentation
The origin of the problem was in several environment variables in defs.h file of WxWidgets library. To make VS Code recognize them on my system (OS X 10.14 Mojave), I had to add "defines" in the c_cpp_properties.json file in the following way:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/src/**",
"/usr/local/include/wx-3.1/**",
"/usr/local/lib/wx/include/osx_cocoa-unicode-3.1",
"/usr/local/lib/wx/**"
],
"defines": [
"WX_PRECOMP",
"__WXOSX_COCOA__",
"_FILE_OFFSET_BITS=64",
"__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1"
],
"forcedInclude": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-9",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
This solution is valid for Mac only. If you experience the same errors with includes or should you have class name squiggles on a different operating system, please find properties for c_cpp_properties.json file in this GitHub repository.
I'm using Visual Studio Code to develop a C++ project, and I have OpenCV installed in a custom location. However, it complains with the following error when I try to include header files from OpenCV:
#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit (/home/.../dev/communication-module/modules/.../.../src/....cpp). C/C++(1696)
cannot open source file "opencv2/core/mat.hpp" C/C++(1696)
Here is a screenshot of the same error:
My .vscode/c_cpp_properties.json file looks as follows:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2",
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"browse": {
"path": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2",
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
And the mat.hpp file is clearly there:
$ ls /opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core | grep mat.hpp
mat.hpp
Still, Visual Studio Code does not pick it up. Why is that? What else should I change for Visual Studio Code to find my OpenCV header files?
The offending line was apparently:
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
After having removed it, it now works. My c_cpp_properties.json config now looks as follows:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include",
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Your include path /opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2 should end with /include .
When you type #include <opencv2/core/mat.hpp> the compiler will search try out /opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/opencv2/core/mat.hpp which will obviously not work.