在 Linux 上安装 NuGet Onnxruntime 版本
在 Ubuntu 20.04 上测试
对于可通过NuGet获得的 onnxruntime 的较新版本,我采用了以下工作流程:下载版本(此处为 1.7.0,但您可以相应地更新链接),并将其安装到~/.local/
. 对于全局(系统范围)安装,您可以将文件放在/usr/local/
.
mkdir /tmp/onnxInstall
cd /tmp/onnxInstall
wget -O onnx_archive.nupkg https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime/1.7.0
unzip onnx_archive.nupkg
cp runtimes/linux-x64/native/libonnxruntime.so ~/.local/lib/
cp -r build/native/include/ ~/.local/include/onnxruntime/
制作
现在,如果您希望能够find_package(onnxruntime)
从您的 Cmake 包中获取,我建议您将我自己创建的 onnx cmake 文件放在~/.local/share/cmake/onnxruntime
. 这些文件是:
cat ~/.local/share/cmake/onnxruntime/onnxruntimeVersion.cmake
:
# Custom cmake version file by jcarius
set(PACKAGE_VERSION "1.7.0")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
cat ~/.local/share/cmake/onnxruntime/onnxruntimeConfig.cmake
# Custom cmake config file by jcarius to enable find_package(onnxruntime) without modifying LIBRARY_PATH and LD_LIBRARY_PATH
#
# This will define the following variables:
# onnxruntime_FOUND -- True if the system has the onnxruntime library
# onnxruntime_INCLUDE_DIRS -- The include directories for onnxruntime
# onnxruntime_LIBRARIES -- Libraries to link against
# onnxruntime_CXX_FLAGS -- Additional (required) compiler flags
include(FindPackageHandleStandardArgs)
# Assume we are in <install-prefix>/share/cmake/onnxruntime/onnxruntimeConfig.cmake
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(onnxruntime_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
set(onnxruntime_INCLUDE_DIRS ${onnxruntime_INSTALL_PREFIX}/include)
set(onnxruntime_LIBRARIES onnxruntime)
set(onnxruntime_CXX_FLAGS "") # no flags needed
find_library(onnxruntime_LIBRARY onnxruntime
PATHS "${onnxruntime_INSTALL_PREFIX}/lib"
)
add_library(onnxruntime SHARED IMPORTED)
set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION "${onnxruntime_LIBRARY}")
set_property(TARGET onnxruntime PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_INCLUDE_DIRS}")
set_property(TARGET onnxruntime PROPERTY INTERFACE_COMPILE_OPTIONS "${onnxruntime_CXX_FLAGS}")
find_package_handle_standard_args(onnxruntime DEFAULT_MSG onnxruntime_LIBRARY onnxruntime_INCLUDE_DIRS)