Eigen/Dense: No such file or directory in VSCode - c++

My main.cpp file
#include <iostream>
#include <vector>
#include <Eigen/Dense>
int main(){
std::vector<int> vec = {5,4,9,1,3,5};
Eigen::MatrixXd my_matrix(2,3);
my_matrix << 4,9,-7,
5,-4,11;
return 0;
}
My c_cpp_properties.json file
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"D:\\Master Program\\Self-Driving-Cars_Udacity\\Part1\\Module_05_Sensor_Fusion\\eigen-3.4.0\\"
],
"compilerPath": "C:/MinGW/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
My task.json file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:\\Master Program\\Self-Driving-Cars_Udacity\\Part1\\Module_05_Sensor_Fusion\\eigen-3.4.0\\"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

Related

No such file or directory while compiling c++ in vscode include onnxruntime api header file

I'm very new to c++. I use VSCode and Ubuntu 18.04. I'm trying to use onnxruntime api in c++ to deploy my net model file.
Firstly I just tested including the onnxruntime api header file
#include <iostream>
#include <ctime>
#include <vector>
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
using namespace std;
int main() {
auto start_time = clock();
cout << "hello world" << endl;
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "test");
auto end_time = clock();
printf("Proceed exit after %.2f seconds\n", static_cast<float>(end_time - start_time) / CLOCKS_PER_SEC);
printf("Done!\n");
return 0;
}
And there's error in compiling my code. The output is
[test.cc 2023-01-05 10:08:28.381]
,,test.cc:4:10: fatal error: onnxruntime/core/session/onnxruntime_cxx_api.h: no such file or directory
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
My onnxruntime directory is '/home/jiahao/git/onnxruntime/include/' and I have added it in tasks.json and c_cpp_properties.json.
Here is my c_cpp_properties.json
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/home/jiahao/git/onnxruntime/include/",
"/home/jiahao/git/onnxruntime/include/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
And here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I", "/home/jiahao/git/onnxruntime/include/",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/g++"
}
]
}
When I Ctrl+click the include line in my code, I will be directed to the correct onnxruntime_cxx_api.h. So I thought the include path is right but I don't know why I cann't compile my code.
I have solved this question. I downloaded the release version of onnxruntime. And in the release package I found header files and .so file. I added the include path in c_cpp_properties.json like this:
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include/",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include/**",
"/usr/include/eigen3/"
],
"browse": {
"path": [
"${workspaceRoot}",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib/",
"/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib/**"
]
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
And I added the include path, .so file path and lib name in tasks.json. Here I also used eigen3 library
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-I", "/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/include",
"-I", "/usr/include/eigen3",
"-L", "/home/jiahao/lib/onnxruntime-linux-x64-1.8.0/lib",
"-l", "onnxruntime",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/g++"
}
]
}
Now I can compile and run my code correctly.

C++ Uniform initialization doesn't work with "expected ';' at end of declaration"

I'm the beginner of C++. I set development environment in vscode in Mac.
But I trapped in variable initialization.
Copy initialization and direct initialization are ok, but uniform initialization doesn't work.
#include <iostream>
int main() {
int a(0);
int b = 0;
int c{0};
int d = {0};
int e;
std::cout << "Hello World";
return 0;
}
In this code, int c{0}; doesn't work. It failed to build.
It printed error: expected ';' at end of declaration
What can I try to solve this problem??
I don't know if it helps, but I'll upload ".vscode".
// c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": ["${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
}
// launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"&&",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 활성 파일 빌드",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "디버거에서 생성된 작업입니다."
}
]
}

fatal error: 'opencv2/opencv.hpp' file not found in macOS VSCode

I plan to use opencv in vscode on macos.
I have configured my c_cpp_properties.json,launch.json and task.json
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/opencv/4.5.3_2/include/opencv4/**",
"/usr/local/Cellar/opencv/4.5.3_2/lib"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/local/opt/opencv/include/opencv4",
"-L/usr/local/opt/opencv/lib",
"-lopencv_core"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
And the editor also has smart completion when I enter the include path
But I still get the file not found error, what should I do?

Include path in c_cpp_properties not working in VS Code

I'm trying to compile a library in C++ for embedded projects using VS Code.
I have set up a few files and can compile the library without issue. The problem comes in with my include path.
My folder structure is:
root
|-.vscode
|-inc
| |-hal
| | |-esp32
| | | |-pin.h
| | | |-eeprom.h
|-src
| |-hal
| | |-esp32
| | | |-pin.cpp
| | | |-eeprom.cpp
When I include "pin.h" in "pin.cpp", I get an error when I include it directly. I need to include it via:
#include "./../../../inc/hal/esp32/pin.h"
In my c_cpp_properties.json file:
{
"configurations": [
{
"name": "esp32",
"includePath": [
"${workspaceFolder}/inc/hal/esp32/**",
"${workspaceFolder}/inc/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/Users/user/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc",
"cStandard": "c17",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-arm64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
Is there another setting I'm missing that is causing this? From my understanding, I should be able to (at best) include "pin.h" directly or (at worst) "inc/hal/esp32/pin.h", but neither of these work.
Additional information:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}
settings.json:
{
"cmake.sourceDirectory": "${workspaceFolder}/.",
"C_Cpp.errorSquiggles": "Enabled"
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
edit:
taks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}

Installing 'Boost' library - using VSCode. Windows 10

I've been trying for several days to add a Path on VSCode to the 'boost' library I've installed for a practice I've got. I can't link up the code implementation with the library downloaded. It keeps printing on the Output: fatal error: boost/signals2/signal.hpp: No such file or directory. This is the c_cpp_properties.json I have:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files/boost/boost_1_66_0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
In which I specify the route to 'boost' in 'includePath'. This is my tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe compilar archivo activo",
"command": "C:\\w64devkit\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lboost_system"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Tarea generada por el depurador."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe compilar archivo activo ver(1)",
"command": "C:\\w64devkit\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lboost_system"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tarea generada por el depurador."
}
],
"version": "2.0.0"
}
And this is my code implementation:
#include <boost/signals2/signal.hpp>
#include <iostream>
using namespace std;
int main() {
cout << "Hello world" << endl;
return 0;
}
Very simple, but the problem is the linking from the compiler to the library. I don't know what to do