#include errors detected for eigen library - c++

I have been trying to use the Eigen library for c++ in VS code. I have seen various answers explaining how to solve the problem. I have opened the c_cpp_properties.json. I have my Eigen library :
But my MinGW shows different files from what I have seen in other answers and tutorials.
Error in code:
After this, what should I do? I tried adding the include path, but I cannot solve this.
Any help is highly appreciated.

You can move the whole Eigen Library to an included folder in IncludePath.
This is an example:
settings.json
"C_Cpp.default.includePath": [
"${workspaceFolder}/**",
"C:\\TDM-GCC-64\\include",
"C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include",
"C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++"
]
For you:
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\x86_64-w64-mingw32\\{Your GCC Version}\\include",
"C:\\MinGW\\lib\\gcc\\x86_64-w64-mingw32\\{Your GCC Version}\\include\\c++"
]
}
]
You can put it in any of the folders like this.

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.

Using clang-tidy to analize embedded GCC project

I'm trying to use clang-tidy to parse my project, compiled by arm-none-eabi-g++.
Unfortunately, clang-tidy is not able to find compiler headers, even when given the include path to them.
My compile_commands.json is
[
{
"directory": "C:/LMA/repo/clang-tidy",
"arguments": [
"arm-none-eabi-c++",
"-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1",
"-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/arm-none-eabi/arm/v5te/hard",
"test.cpp"
],
"file": "./test.cpp" } ]
And the example test.cpp file is:
#include <cstdint>
#include <cstdlib>
int test()
{
int temp;
return 0;
}
Clang-tidy shows error:
C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1\cstdlib:75:15: error: 'stdlib.h' file not found [clang-diagnostic-error]
#include_next <stdlib.h>
So, it properly finds and includes cstdlib, however it is not able to find stdint.h, which is located in the exactly same folder. What's even more irritaiting, it does not include stdlib.h, even when I add
-include C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/stdlib.h
to compiler arguments in order to force preinclude.
Any suggestions how to fix this issue are very much appreciated.
This is a bit old, but I was having a similar issue so I figured I'd report an answer here in case anyone else comes across this while searching. It appears clang doesn't know where to find the standard library headers when compiling using arm-none-eabi. I succeeded by simply adding them.
In your case you're still missing the C headers directory, so you need to add this:
C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/
(assuming the directory structure is similar to mine).
So your compile_commands.json would be:
[ {
"directory": "C:/LMA/repo/clang-tidy",
"arguments": [
"arm-none-eabi-g++",
"-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include",
"-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1",
"-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/arm-none-eabi/arm/v5te/hard",
"test.cpp"
],
"file": "./test.cpp"
} ]
You should also have arm-none-eabi-g++ instead of arm-none-eabi-c++ I believe.

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!!

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.

I cannot figure out the "undefined reference to Winmain#16 error"

Before I start, I know there are a lot of other questions on stack that are the same as mine. Trust me, I've checked them all, and I wouldn't be asking this question if they had helped me in any way shape or form. Also I would very much like an easy to understand answer, because while looking at the other questions, it took me 10 minutes of looking at them just to figure out what they meant. That being said, let's get to my problem.
I am trying to get SDL to work with Visual Studio Code (Not Visual Studio. My computer doesn't have enough space for Visual Studio or I'd be using it.) I am in the tasks.json file trying to link the SDL2.lib library to the file I'm working with, main.cpp (I'm using c++). I have moved all the files in the SDL include and lib folders to be loose in my mingw bin folder. This is my tasks.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"-c",
"C:/MinGW/bin/main.cpp",
"C:/MinGW/bin/SDL2.lib",
"-lmingw32"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
]
}
And here is my main.cpp file:
#include "windows.h"
#include "SDL.h"
#include <iostream>
int main(int argc, char** argv) {
SDL_Init(SDL_INIT_EVERYTHING);
return 0;
}
I get the following error:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
From what I can tell, this error is fairly common, but I have been keeping track, and over the past two weeks, I have tried 37 different ways to solve this problem (including the solutions to the other posts about this). I don't know what the problem is, but maybe someone here can figure it out. I have posted this in four other forums with no responses and I am so lost. It's really hard to be enthusiastic right now, but please respond and thank you in advance!
Try adding this line before your SDL include:
#define SDL_MAIN_HANDLED
Look here for more details:
undefined reference to `WinMain#16'