1

I am trying to build onnxruntime from source on Linux. According to this instruction I have successfully built python wheels and shared libs. But I have not seen headers for C API.

There is a build option --build_csharp which seems to enable C#/C packages. I tried to add this option but got following errors.

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

I installed dotnet-sdk-3.1 but still got this error. Can I ask how to properly generate onnxruntime C API on Linux? Thanks!

lee670523
  • 21
  • 2
  • **Explain what "generate a C API" means to you.** On Linux, C source code are files (conventionnally named `*.c` or `*.h`). Your [GCC](http://gcc.gnu.org/) compiler is reading them, and some of your C programs (once compiled into an [ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) executable could write them (e.g. with [stdio(3)](https://man7.org/linux/man-pages/man3/stdio.3.html)...) – Basile Starynkevitch Jun 28 '20 at 06:25
  • Read [*Modern C*](https://modernc.gforge.inria.fr/), then [syscalls(2)](https://man7.org/linux/man-pages/man2/syscalls.2.html) and the documentation of *every* C function you are using (e.g. [from here](https://en.cppreference.com/w/c)...) and of your C compiler (e.g. [GCC](http://gcc.gnu.org/) or [Clang](http://clang.llvm.org/)...). Read the documentation of [GDB](https://www.gnu.org/software/gdb/) For your next question, provide some [mre] – Basile Starynkevitch Jun 28 '20 at 06:28
  • @BasileStarynkevitch Hi Basile, thanks for your comment. What I am trying to do is to build onnxruntime, which is a library for machine learning inference. The generated build files include shared libs and python wheels. The problem is there is no C headers generated, and I can't call those shared libs in C. Maybe I should remove the linux tag because it is actually a pure onnxruntime issue. – lee670523 Jun 28 '20 at 07:20
  • On Linux, C# could mean https://www.mono-project.com/ ; have you installed it? And of course, C and C# are *very* different languages. C is defined by the C11 standard [n1570](https://web.cs.dal.ca/~vlado/pl/C_Standard_2011-n1570.pdf) and [GCC](http://gcc.gnu.org/) is a C compiler. Regarding shared libraries, read Drepper's [*How to write shared libraries*](https://www.akkadia.org/drepper/dsohowto.pdf) paper. You would use `gcc -fPIC -shared -Wall` to compile it – Basile Starynkevitch Jun 28 '20 at 12:24

1 Answers1

2

Please try the following steps:

- 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.
Kumar Arnav
  • 301
  • 2
  • 13