英文:
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 an 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 can't compile my code.
英文:
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.
答案1
得分: 0
我已解决了这个问题。我下载了onnxruntime的发布版本。在发布包中,我找到了头文件和.so文件。我在c_cpp_properties.json中添加了包含路径,如下所示:
{
"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
}
我还在tasks.json中添加了包含路径、.so文件路径和库名称。在这里,我还使用了eigen3库。
{
"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++"
}
]
}
现在,我可以正确编译和运行我的代码。
希望这能帮助你。如果有其他问题,请告诉我。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论