记一次部署onnxruntime库的小众bug
将onnxruntime库和cuda版本匹配好后,我将其安装在/usr/local/目录下,同时在项目的CMakeLists.txt文件下指定find_package(onnxruntime REQUIRED),然后进行编译操作,发现find_package无法找到相应的库,报错如下:
CMake Error at quadruped/CMakeLists.txt:40 (find_package):
By not providing "Findonnxruntime.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"onnxruntime", but CMake did not find one.
Could not find a package configuration file provided by "onnxruntime" with
any of the following names:
onnxruntimeConfig.cmake
onnxruntime-config.cmake
Add the installation prefix of "onnxruntime" to CMAKE_PREFIX_PATH or set
"onnxruntime_DIR" to a directory containing one of the above files. If
"onnxruntime" provides a separate development package or SDK, be sure it
has been installed.
随后我将find_package改为如下代码:
set(onnxruntime_DIR "/usr/local/onnxruntime")
set(onnxruntime_INCLUDE_DIRS "${onnxruntime_DIR}/include")
set(onnxruntime_LIBRARIES "${onnxruntime_DIR}/lib")
include_directories(${onnxruntime_INCLUDE_DIRS})
link_directories(${onnxruntime_LIBRARIES})
虽然cmake不报错了,但编译到最后进行链接的时候还是报了个错,如下所示:
undefined reference to `OrtGetApiBase' collect2: error: ld returned 1 exit status
查了半天,最终发现是lib库要指定到文件,不能仅仅是路径,遂将onnxruntime_LINBRARIES改为:
set(onnxruntime_LIBRARIES "${onnxruntime_DIR}/lib/libonnxruntime.so")
之后编译通过。