Linking onnx-light in C++#

This page summarizes the design used to consume onnx-light as a standalone C++ library from another project.

Runnable examples are available in C++ onnx-light examples, including examples/load_onnx_light_time and examples/check_onnx_light_model.

Alternative without install#

For monorepos or local development, a downstream CMake project can also include onnx-light directly:

set(ONNX_LIGHT_BUILD_PYTHON OFF CACHE BOOL "" FORCE)
add_subdirectory(path/to/onnx-light)
target_link_libraries(my_target PRIVATE lib_onnx_lib)

Use the in-tree lib_onnx_proto target instead when only proto parsing/serialization is needed. This uses the in-tree build targets instead of find_package.

Excerpt from the example project#

The example CMake project in examples/load_onnx_light_time uses exactly that pattern:

cmake_minimum_required(VERSION 3.15)
project(load_onnx_light_time LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(onnx_light REQUIRED)

add_executable(load_onnx_light_time main.cc)
target_link_libraries(load_onnx_light_time PRIVATE onnx_light::lib_onnx_proto)

See also#