VSC - IntelliSense marks boolean operator as errors - c++

IntelliSense is incorrectly marking boolean operators (and, or, etc.) As errors. Here is an example:
This is my c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
Anyone knows why this is happening?

With Visual C++, it looks like you need to add #include <iso646.h>.
C++ specifies bitand as an alternative spelling for &. In C, the alternative spelling is provided as a macro in the <iso646.h> header. In C++, the alternative spelling is a keyword; use of <iso646.h> or the C++ equivalent is deprecated. In Microsoft C++, the /permissive- or /Za compiler option is required to enable the alternative spelling.
After including the header file, it no longer errors:
Wikipedia also cites:
Some compilers, such as Microsoft Visual C++ have, at least in the past, required the header to be included in order to use these identifiers.

Related

Unable to include local C++ dependencies in VSCode

I am having an issue with writing code for my Robotic Operating System (ROS) project, however it's more related to dependency inclusion. Here is as far as I got with the code:
// ROS
#include <ros/ros.h>
// MoveIt
#include "moveit/moveit_ros/planning_interface/planning_scene_interface/include/*"
#include "moveit/moveit_ros/planning_scene_interface/planning_scene_interface.h"
#include <moveit/move_group_interface/move_group_interface.h>
// TF2
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
// The circle constant tau = 2*pi. One tau is one rotation in radians.
const double tau = 2 * M_PI;
int main(){
}
The issue is that dependency 2 through to 4 are not identified by VSCode. I attempted to include the necessary path within c_cpp_properties.json for dependency 2 as such:
"/home/george/ws_moveit/src/moveit/moveit_ros/planning_interface/planning_scene_interface/include/**"
The full c_cpp_properties.json looks as such:
{
"configurations": [
{
"browse": {
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/home/george/ws_moveit/devel/include/**",
"/opt/ros/noetic/include/**",
"/home/george/ws_moveit/src/moveit/moveit_planners/chomp/chomp_motion_planner/include/**",
"/home/george/ws_moveit/src/geometric_shapes/include/**",
"/home/george/ws_moveit/src/moveit/moveit_planners/chomp/chomp_interface/include/**",
"/home/george/ws_moveit/src/moveit_resources/prbt_ikfast_manipulator_plugin/include/**",
"/home/george/ws_moveit/src/moveit/moveit_ros/benchmarks/include/**",
"/home/george/ws_moveit/src/moveit/moveit_plugins/moveit_ros_control_interface/include/**",
"/home/george/ws_moveit/src/moveit/moveit_ros/move_group/include/**",
"/home/george/ws_moveit/src/moveit/moveit_ros/occupancy_map_monitor/include/**",
"/home/george/ws_moveit/src/moveit/moveit_ros/robot_interaction/include/**",
"/home/george/ws_moveit/src/moveit/moveit_ros/moveit_servo/include/**",
"/home/george/ws_moveit/src/moveit/moveit_setup_assistant/include/**",
"/home/george/ws_moveit/src/moveit/moveit_plugins/moveit_simple_controller_manager/include/**",
"/home/george/ws_moveit/src/moveit_visual_tools/include/**",
"/home/george/ws_moveit/src/pick_place/include/**",
"/home/george/ws_moveit/src/moveit/moveit_planners/pilz_industrial_motion_planner/include/**",
"/home/george/ws_moveit/src/moveit/moveit_planners/pilz_industrial_motion_planner_testutils/include/**",
"/home/george/ws_moveit/src/rviz_visual_tools/include/**",
"/home/george/ws_moveit/src/srdfdom/include/**",
"/usr/include/**",
"/opt/ros/noetic/include",
"/home/george/ws_moveit/src/moveit/moveit_ros/planning_interface/planning_scene_interface/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
This hasn't resolved my issue.
The way the packages are structured could be found here: https://github.com/ros-planning/moveit. It is essentially identical to the way I have them structured on my drive, with the the difference being the inclusion of the home/user directory.
The file in question should be located here:
https://github.com/ros-planning/moveit/tree/master/moveit_ros/planning_interface/planning_scene_interface/include/moveit/planning_scene_interface
Am I missing some detail or made an error?
#include "moveit/moveit_ros/planning_interface/planning_scene_interface/include/*"
Wildcards are not allowed in include statements, unless you have a very... weird preprocessor.
Reference the files you want to include directly, or use a master header file that directly contains all the files you want to include.

WebSocket #include errors detected. Please update your includePath

I'm trying to work on WebSocket in C++ using websocketpp library. I have cloned this library https://github.com/zaphoyd/websocketpp in my system and build it using "cmake -G "MinGW Makefiles". Now the source code which I have created outside this repository.
#include <iostream>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg) {
std::cout << msg->get_payload() << std::endl;
}
int main() {
server print_server;
print_server.set_message_handler(&on_message);
print_server.init_asio();
print_server.listen(9002);
print_server.start_accept();
print_server.run();
}
is throwing error:
fatal error: websocketpp/config/asio_no_tls.hpp: No such file or directory
#include <websocketpp/config/asio_no_tls.hpp>
although this file is available in directory. Since I'm not getting any issue with this line #include <websocketpp/server.hpp>. Clicking on option more I found this error
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit
Anyone help it out with what needs to be done. I'm editing it in VS code and using MinGW.
this is the properties.json file
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4

Visual Studio Code - Include Path Problems Header Files C++ (MinGW)

I am pretty new to programm in C++ so please don't judge my problems with setting up my "Visual Studio Code" environment. I am trying to use the blaze math packages to solve quadratic programming problems. With the MinGW GCC I can compile the testfiles of blaze successfully via cmd and thus I want to use the GCC for VS Code.
OS: Windows 10.0.19041
GCC: gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 7.3.0 || (cmd: gcc --version)
VS Code Extensions: C/C++ 0.27.1
Firstly I went through the VS Code tutorial for MinGW:
https://code.visualstudio.com/docs/cpp/config-mingw
This worked fine so I can easily compile my helloworld.cpp. The resulting tasks.json file looks like this
tasks.json.
As my package manager (for blaze or other packages) i use the vspkg-git:
https://learn.microsoft.com/en-us/cpp/build/vcpkg?view=msvc-160
Thus I am programming on Windows I can't use the "integrate" command to add the path to the includepath. So I have to do this manually.
My packages are in the folder with the absolute path
C:\Users\Johannes\Desktop\Masterthesis\vcpkg\vcpkg\packages
So I added the path on the "c_cpp_propertier.json"-file
{
"configurations": [
{
"name": "GCC",
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceFolder}",
"C:/Users/Johannes/Desktop/Masterthesis/vcpkg/vcpkg/packages/**"
],
"compilerPath": "C:/Program Files/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/bin/g++.exe",
"browse": {
"path": []
}
}
],
"version": 4
}
In the folder are several packages therefor I added the "/**" at the end of the path to enable the recursive search for header files.
My 'helloworld.cpp' file looks like this
#include <iostream>
#include <vector>
#include <string>
//#include <blaze/Math.h>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the
C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
My problem is that when I try to include a header-file from this path for example Math.h Visual Studio throws an Error
blaze/Math.h: No such file or directory
But when I right-click on the include and click "Go to Definition" VS Code opens the file. Optionbar and the opened file.
The Log-Diagnostics gives that information.
I guess someone that has experience with MinGW and additional packages in VS Code will solve that problem very simple, but I have read nearly every thread about those problems and didn't find anything matching mine.
Okay, i got the answere. The include path of the "c_cpp_properties.json" file is only for IntelliSense. This means that Visual Studio Code will find this packages and IntelliSense will suggest you the available headers from the pathes. This does not mean that the compiler can find these pathes. Therefor you have to add the pathes to the "tasks.json" file. As you can see above in the photo of the "tasks.json" file, there is a field called "args" which means "arguments". Those are the compiler arguments. You have to add the Path there too in Format "-I","C:/PathYouWishToAdd". This works fine!!

VSCode IntelliSense not recognising SDL_image extension library for SDL framework

I am trying to include the SDL_image extension library to SDL.framework in my project but VScode's IntelliSense keeps underlining my #include<SDL_image.h> with error lines. It produces the following error:
cannot open source file "SDL2/SDL.h" (dependency of "SDL_image.h")
I was successfully able to edit the c_cpp_properties.json includePath so IntelliSense recognised the SDL framework, but when trying to do the same thing with SLD_image it failed.
This is my c_cpp_properties.json file:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Library/Frameworks/SDL2_image.framework/Headers",
"/Library/Frameworks/SDL2.framework/Headers",
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
The problem wasn't with the c_cpp_properties.json but the SDL_image.h file. If you are using VScode (despite being on a mac) and encountering the same issue with IntelliSense, change the following include statements inside SDL_image.h from this:
#include <SDL2/SDL.h>
#include <SDL2/SDL_version.h>
#include <SDL2/begin_code.h>
#include <SDL2/close_code.h>
to this:
#include <SDL.h>
#include <SDL_version.h>
#include <begin_code.h>
#include <close_code.h>
Of note, I had the exact opposite issue working on Windows 10, just changed them arouind the other way.
From:
#include <SDL.h>
#include <SDL_version.h>
#include <begin_code.h>
#include <close_code.h>
To:
#include <SDL2/SDL.h>
#include <SDL2/SDL_version.h>
#include <SDL2/begin_code.h>
#include <SDL2/close_code.h>
as this is the exact path to the .h files

Incomplete type is not allowed (c++ VSCODE) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have simply created an Array a using container class. However, VScode's IntelliSense is showing an error. Here's an implementation of selection sort.
the contents of the c_cpp_properties.json file are as follows
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.16299.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
the code compiles and runs successfully. How do I fix the incorrect IntelliSense error?
Stop including bits/stdc++.h.
That's an implementation header for some toolchains. It's not for you.
Include the proper header instead:
#include <array>
(It's likely that your Intellisense engine does not have access to this internal header from Linuxy platforms.)
By the way, you're not allowed to choose names that begin with two underscores. So stop that too.