【OnnxRuntime】在linux下编译并安装C++版本的onnx-runtime

目录

安装C++接口的onnx-runtime

安装依赖项:

安装CMake:可以通过包管理器(如apt、yum等)安装CMake。

安装C++编译器:确保系统中已安装C++编译器,如GCC或Clang。

下载源文件

克隆ONNX Runtime的GitHub仓库,指定版本是为了适配python3.8:

bash 复制代码
git clone --branch v1.5.2 --recursive https://gitee.com/lee-zq/onnxruntime.git

构建ONNX Runtime

进入ONNX Runtime的源代码目录:

// 首先创建一个conda环境,因为./build.sh实际上调用的是./tools/cl_build/build.py

bash 复制代码
cd onnxruntime
conda create -n onnxruntime python=3.8
./build.sh --skip_tests --config Release --build_shared_lib --parallel

注意,若配合cuda使用,命令行末尾应添加

bash 复制代码
-cuda_home /usr/local/cuda-11.3 --cudnn_home /usr/local/cuda-11.3

注意,编译前,确保机器装有linux环境:

bash 复制代码
sudo apt-get install build-essential

这将使用所有可用的CPU核心进行编译。如果希望使用指定数量的核心,可以将$(nproc)替换为所需的核心数量。

安装ONNX Runtime

运行以下命令进行安装:

bash 复制代码
cd /build/Linux/Release
sudo make install

通过按照上述步骤,您应该能够在Linux上成功安装ONNX Runtime。请注意,安装过程中可能需要根据您的系统和需求进行适当的调整。

cpp 复制代码
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/include/onnxruntime/core/common
-- Installing: /usr/local/include/onnxruntime/core/common/code_location.h
-- Installing: /usr/local/include/onnxruntime/core/common/common.h
-- Installing: /usr/local/include/onnxruntime/core/common/const_pointer_container.h
-- Installing: /usr/local/include/onnxruntime/core/common/eigen_common_wrapper.h
-- Installing: /usr/local/include/onnxruntime/core/common/exceptions.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging
-- Installing: /usr/local/include/onnxruntime/core/common/logging/capture.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/isink.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/logging.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/macros.h
-- Installing: /usr/local/include/onnxruntime/core/common/logging/severity.h
-- Installing: /usr/local/include/onnxruntime/core/common/make_unique.h
-- Installing: /usr/local/include/onnxruntime/core/common/optional.h
-- Installing: /usr/local/include/onnxruntime/core/common/status.h
-- Installing: /usr/local/include/onnxruntime/core/graph
-- Installing: /usr/local/include/onnxruntime/core/graph/basic_types.h
-- Installing: /usr/local/include/onnxruntime/core/graph/constants.h
-- Installing: /usr/local/include/onnxruntime/core/graph/function.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph_nodes.h
-- Installing: /usr/local/include/onnxruntime/core/graph/graph_viewer.h
-- Installing: /usr/local/include/onnxruntime/core/graph/indexed_sub_graph.h
-- Installing: /usr/local/include/onnxruntime/core/graph/node_arg.h
-- Installing: /usr/local/include/onnxruntime/core/graph/onnx_protobuf.h
-- Installing: /usr/local/include/onnxruntime/core/graph/schema_registry.h
-- Installing: /usr/local/include/onnxruntime/core/framework
-- Installing: /usr/local/include/onnxruntime/core/framework/alloc_kind.h
-- Installing: /usr/local/include/onnxruntime/core/framework/allocator.h
-- Installing: /usr/local/include/onnxruntime/core/framework/customregistry.h
-- Installing: /usr/local/include/onnxruntime/core/framework/data_types.h
-- Installing: /usr/local/include/onnxruntime/core/framework/data_types_internal.h
-- Installing: /usr/local/include/onnxruntime/core/framework/endian.h
-- Installing: /usr/local/include/onnxruntime/core/framework/execution_provider.h
-- Installing: /usr/local/include/onnxruntime/core/framework/fence.h
-- Installing: /usr/local/include/onnxruntime/core/framework/framework_common.h
-- Installing: /usr/local/include/onnxruntime/core/framework/func_api.h
-- Installing: /usr/local/include/onnxruntime/core/framework/kernel_def_builder.h
-- Installing: /usr/local/include/onnxruntime/core/framework/kernel_registry.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ml_value.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_kernel.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_kernel_info.h
-- Installing: /usr/local/include/onnxruntime/core/framework/op_node_proto_helper.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ortdevice.h
-- Installing: /usr/local/include/onnxruntime/core/framework/ortmemoryinfo.h
-- Installing: /usr/local/include/onnxruntime/core/framework/run_options.h
-- Installing: /usr/local/include/onnxruntime/core/framework/sparse_tensor.h
-- Installing: /usr/local/include/onnxruntime/core/framework/tensor.h
-- Installing: /usr/local/include/onnxruntime/core/framework/tensor_shape.h
-- Installing: /usr/local/include/onnxruntime/core/providers/cpu
-- Installing: /usr/local/include/onnxruntime/core/providers/cpu/cpu_provider_factory.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer_level.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/graph_transformer_utils.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/rewrite_rule.h
-- Installing: /usr/local/include/onnxruntime/core/optimizer/rule_based_graph_transformer.h
-- Installing: /usr/local/include/onnxruntime/core/session
-- Installing: /usr/local/include/onnxruntime/core/session/automl_data_containers.h
-- Installing: /usr/local/include/onnxruntime/core/session/environment.h
-- Installing: /usr/local/include/onnxruntime/core/session/experimental_onnxruntime_cxx_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/experimental_onnxruntime_cxx_inline.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_c_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_cxx_api.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_cxx_inline.h
-- Installing: /usr/local/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
-- Installing: /usr/local/lib/libonnxruntime.so.1.5.2
-- Installing: /usr/local/lib/libonnxruntime.so
-- Installing: /usr/local/bin/onnx_test_runner

安装完成。

相关推荐
睡觉然后上课10 分钟前
c基础面试题
c语言·开发语言·c++·面试
qing_04060317 分钟前
C++——继承
开发语言·c++·继承
ya888g18 分钟前
GESP C++四级样题卷
java·c++·算法
fasewer33 分钟前
第五章 linux实战-挖矿 二
linux·运维·服务器
小叶学C++34 分钟前
【C++】类与对象(下)
java·开发语言·c++
NuyoahC1 小时前
算法笔记(十一)——优先级队列(堆)
c++·笔记·算法·优先级队列
楚灵魈1 小时前
[Linux]从零开始的网站搭建教程
linux·运维·服务器
小小不董1 小时前
《Linux从小白到高手》理论篇:深入理解Linux的网络管理
linux·运维·服务器·数据库·php·dba
FL16238631292 小时前
[C++]使用纯opencv部署yolov11-pose姿态估计onnx模型
c++·opencv·yolo
sukalot2 小时前
windows C++-使用任务和 XML HTTP 请求进行连接(一)
c++·windows