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
Related
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.
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"
}
Every time i want to run my c++ code it show unable to debugging and not implemented.
please help to solve my problems
it seems error in launch.jsons / task.jsons / c_cpp_properties.jsons
please help me to resolve these error . I am new in coding and i am stuck in this from 4 days .
launch.jsons
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "C:\\Users\\Sumit\\Desktop\\vs code Projects\\CPP Projects\\hello_world.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGW\\bin",
"environment": [],
"console": "externalTerminal"
}
]
}
task.jsons
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
c_cpp_properties.jsons
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}
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?
I get Include file not found in browse.path.
However the IDE sees the path as I am typing #include "ntrip_caster.h".
It gave the header in a list but than a couple seconds later shows it can't find it once it is in the code. How to direct VS to where the headers are ???
Also note this is OS Ubuntu on WSL... I don't know if there is problems with paths with WSL Ubuntu.
I did the following: none worked...
go to File -> Preferences -> Settings in VS Code and change "C_Cpp.intelliSenseEngine": "Default" to "C_Cpp.intelliSenseEngine": "Tag Parser".
//#include "ntrip_caster.h"
//#include "/home/xxx/ntrip/src/ntrip_caster.h"
//#include "../src/ntrip_caster.h"
//#include "ntrip_caster.h"
//#include "ntrip_caster.h"
//#include "${HOME}/xxx/ntrip/src/ntrip_caster.h"
#include "ntrip_caster.h"
{
"configurations": [
{
"name": "Linux",
"includePath": [
//"${workspaceFolder}/**",
"/home/xxx/ntrip/src/"
//"${workspaceFolder}/nn"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
//"cStandard": "gnu17",
"cStandard": "c11",
//"cppStandard": "gnu++14",
"cppStandard": "c++17",
//"intelliSenseMode": "linux-gcc-x64"
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
//"-I./include -std=c++11 -pthread lpthread",
"-std=c++11 -pthread lpthread",
//"${file}",
//"/home/xxx/ntrip/src/mount_point.h",
"/home/xxx/ntrip/src/ntrip_caster.cc",
//"/home/xxx/ntrip/src/ntrip_caster.h",
"/home/xxx/ntrip/src/ntrip_util.cc",
//"/home/xxx/ntrip/src/ntrip_util.h",
"/home/xxx/ntrip/examples/ntrip_caster.cc",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}