Configure VsCode Include Path for Protobuf installed with gRPC - c++

I am using VsCode. I have gprc natively installed in the directory /grpc. I used their quickstart guide I have all the grpc header files needed; however, I cannot find all the files for protobuf. Within grpc I notice there is a /thirdparty/protobuf folder that I try to include but some artifacts are not found.
To note it compiles and runs perfectly. I am just setting up the include settings for c_cpp_properties.json for vscode linter.
Here is what I have
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${default}",
"${workspaceFolder}/include",
"${workspaceFolder}/grpc",
"${workspaceFolder}/build/protos",
"${workspaceFolder}",
"${workspaceFolder}/lib**",
"/grpc/include",
"/grpc/third_party",
"/grpc/third_party/protobuf"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu18",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
My protobufs cannot files such as the following for the generated protobuf files.
#include <google/protobuf/port_def.inc>
#include <google/protobuf/port_undef.inc>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/inlined_string_field.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
Another screenshot to sanity check that grpc includes from /grpc/includes are properly recognized by vscode.
Update
Download protobuf source file from github then include the path below in the json settings file.
"/protobuf/src/google/protobuf"

Related

Issue including QT files in VSCode Manjaro Linux

I have been working with c++ for a few years now and I have decided to try my hands at simple GUI development. I know that c++ is not generally regarded as a great language to do GUI development, but I am very comfortable with it and have had success using c++ with QT Creator at making simple GUIs. I have seen people running QT code on Visual Studio Code and I am currently trying to set it up for myself. I looked around on the internet for some guides or at least some instruction, but what little I found was either outdated or designed for a different os (I use Manjaro Linux). Any help would be greatly appreciated!
c_cpp_properties.json file:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/qt6/**",
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
game.h (Auto-generated QT code from starting a project)
#ifndef GAME_H
#define GAME_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class Game; }
QT_END_NAMESPACE
class Game : public QMainWindow
{
Q_OBJECT
public:
Game(QWidget *parent = nullptr);
~Game();
private:
Ui::Game *ui;
};
#endif // GAME_H
The error I am getting: cannot open source file "QMainWindow" on line 4 of game.h.
I tried to address the problem by adding /usr/include/qt6 to my configurations file, but that didn't help anything. I am sure this is a fairly simple include issue, so thank you for your patience!

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