【问题标题】:How to generate C API for onnxruntime on Linux如何在 Linux 上为 onnxruntime 生成 C API
【发布时间】:2020-06-28 02:38:50
【问题描述】:

我正在尝试从 Linux 上的源代码构建 onnxruntime。根据这个instruction 我已经成功构建了python 轮子和共享库。但我还没有看到 C API 的标头。

有一个构建选项--build_csharp 似乎启用了 C#/C 包。我尝试添加此选项,但出现以下错误。

CMake Warning at CMakeLists.txt:137 (message):
Language Csharp is not found in the system

我安装了 dotnet-sdk-3.1 但仍然出现此错误。请问如何在Linux上正确生成onnxruntime C API?谢谢!

【问题讨论】:

  • 解释“生成 C API”对您意味着什么。 在 Linux 上,C 源代码是文件(通常命名为 *.c*.h)。您的 GCC 编译器正在读取它们,而您的一些 C 程序(一旦编译成 ELF 可执行文件就可以编写它们(例如使用 stdio(3)...)
  • 阅读Modern C,然后阅读syscalls(2) 以及您正在使用的每个 C 函数的文档(例如from here...)和您的C 编译器(例如GCCClang...)。阅读GDB 的文档对于您的下一个问题,请提供一些minimal reproducible example
  • @BasileStarynkevitch 嗨,Basile,感谢您的评论。我正在尝试做的是构建 onnxruntime,这是一个用于机器学习推理的库。生成的构建文件包括共享库和 python 轮子。问题是没有生成 C 头文件,我不能在 C 中调用那些共享库。也许我应该删除 linux 标签,因为它实际上是一个纯粹的 onnxruntime 问题。
  • 在 Linux 上,C# 可能意味着 mono-project.com ;你安装了吗?当然,C 和 C# 是 非常 不同的语言。 C 由 C11 标准 n1570 定义,GCC 是 C 编译器。关于共享库,请阅读 Drepper 的 How to write shared libraries 论文。你可以使用gcc -fPIC -shared -Wall 来编译它

标签: onnxruntime


【解决方案1】:

请尝试以下步骤:

- Steps to build ONNX from source code:
1. git clone --recursive https://github.com/Microsoft/onnxruntime
2. Get the commit ID of the version you want to build (In case you want older version)
3. git checkout "your commitID"
4. Install the required version of Cmake on your system
6. Run: <path>\build.sh --config Release --build_shared_lib --parallel
7. A build folder will be created in the onnxruntime.
5. Get the onnxruntime.dll from the dir: \onnxruntime\build\Windows\Release\Release
6. Get the required headers (onnxruntime_c_api.h, onnxruntime_cxx_api.h, onnxruntime_cxx_inline.h)
from the dir: \onnxruntime\include\onnxruntime\core\session and put it in the unit location.

【讨论】:

    猜你喜欢
    • 2019-07-15
    • 2020-11-03
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    相关资源
    最近更新 更多