Practical overview
When it fits
Use onnx2c when a trained model is available in ONNX format and a microcontroller project is already in place, and you want generated C inference code rather than running a general model runtime on the device.
Who it is for
- Embedded developers integrating trained ONNX models into microcontroller projects.
- TinyML developers who need model inference code with compile-time buffer allocation.
Documented uses
- Convert an ONNX model file into C source for an embedded project.
- Call the generated model entry function from a microcontroller application.
- Explore whether an ONNX model may fit an MCU target using the documented helper script.
Requirements & limits
- The workflow requires an ONNX model and an existing project to integrate the generated code.
- Building the converter requires Protocol Buffers dependencies, submodules and CMake.
- Generated code has no stated library requirement beyond the standard C math library; floating-point hardware is recommended.
- The project reports partial ONNX operator support, so model operator coverage matters.
- The project documents inference conversion, not backpropagation or accelerator support.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Convert an ONNX model into C source
Generate a C file from an ONNX model for inclusion in an existing project.
Before you start
- An ONNX model file.
- A built onnx2c binary.
Steps
Run
./onnx2c [your ONNX model file] > model.c.Include the generated C file in the project and call its
entry(...)function from the main program.
Expected outcome
A generated C source file containing the model inference function.
Guide limitations
- ONNX operator coverage is partial; the README says 91 of 166 operators are at least partially implemented.
- Generated code requires the standard C math library; floating-point hardware is recommended.
Build the onnx2c command-line compiler
Compile the repository into the onnx2c binary used to convert ONNX files.
Before you start
- Protocol Buffers libraries and compiler.
- Git, submodule support, CMake and make.
Steps
Clone
https://github.com/kraiskil/onnx2c.gitand enter the repository directory.Run the command below.
git submodule update --initCreate a build directory, enter it, run
cmake -DCMAKE_BUILD_TYPE=Release .., then run the command below.make onnx2c
Expected outcome
The build produces an `onnx2c` binary.
Guide limitations
- The README notes a Release-build issue on at least Protocol Buffers 3.6 and suggests Debug mode or updating Protocol Buffers.
- For Protocol Buffers 3.6 or earlier, the README describes modifying
onnx/onnx/onnx.proto; versions between 3.6 and 3.12 are uninvestigated.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 14 November 2026
- Original website title
- kraiskil/onnx2c · Official homepage title · retained in its source language

