Build Onnxruntime With Bazel

Overview

背景

需要使用bazel build onnxruntime

但是onnxruntime本身没有提供bazel相关的配置

作为单独的repo

将onnxruntime的包下载下来解压

主要的坑点在于动态库必须写全版本号,不然无法成功导入 完整的BUILD.bazel文件为

 1
 2
 3
 4cc_import(
 5  name = "ort_lib",
 6  hdrs = glob(["onnxruntime-linux-x64-1.13.1/include/**/*.h"]),
 7  # FIXME: 这里的动态库必须写全版本号,不然会出现error: undefined reference to 'OrtGetApiBase'
 8  shared_library = "onnxruntime-linux-x64-1.13.1/lib/libonnxruntime.so.1.13.1",
 9)
10
11cc_library(
12  name = "ort",
13  hdrs = glob(["onnxruntime-linux-x64-1.13.1/include/**/*.h"]),
14  visibility = ["//visibility:public"],
15  # copts = ["-Ionnxruntime-linux-x64-1.13.1/include"],
16  strip_include_prefix = "onnxruntime-linux-x64-1.13.1/include",
17  deps = [":ort_lib"]
18)
19
20
21
22cc_binary(
23  name = "demo",
24  srcs = ["demo.cc"],
25  deps = [":ort"],
26  # linkstatic=False,
27  # copts = ["-Ionnxruntime-linux-x64-1.13.1/include"],
28)
29

cc文件中,头文件的路径为

1#include "onnxruntime_cxx_api.h"