在vscode include onnxruntime API头文件中编译c++时没有此类文件或目录

x6yk4ghg  于 2023-01-15  发布在  Vscode
关注(0)|答案(1)|浏览(795)

我对c非常陌生,我使用VSCode和Ubuntu 18.04,我正在尝试使用c中的onnxruntime API来部署我的net模型文件。
首先,我测试了onnxruntime API头文件

#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;
}

编译代码时出错。输出为

[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.

我的onnxruntime目录是'/home/jiahao/git/onnxruntime/include/',我已经将它添加到tasks.json和c_cpp_properties. json中。
下面是我的c_cpp_属性. 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
}

这是我的任务。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++"
        }
    ]
}

当我按住Ctrl键并单击代码中的include行时,我将被定向到正确的onnxruntime_cxx_api. h.所以我认为include路径是正确的,但我不知道为什么我不能编译代码.

ovfsdjhp

ovfsdjhp1#

我已经解决了这个问题,我下载了onnxruntime的发布版本,在发布包中我发现了头文件和.so文件,我在c_cpp_properties. json中添加了include路径,如下所示:

{
    "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中添加了include路径、.so文件路径和库名称。

{
    "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.

相关问题