CMake Error at CMakeLists.txt:3 (cmake_minimum_required):
CMake 3.13 or higher is required. You are running version 3.2.2
-- Configuring incomplete, errors occurred!
onnx-tensorrt v7.0以上版本需求cmake版本>3.13,导致无法编译。
解决方法升级cmake版本:
1)下载安装包并解压
wget https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz
tar -zxvf cmake-3.13.5-Linux-x86_64.tar.gz
#sudo mv cmake-3.13.5-Linux-x86_64 /opt/cmake-3.13.5
#ln -sf /opt/cmake-3.13.5/bin/* /usr/bin/
#./cmake-3.13.5-Linux-x86_64/bin/cmake --version # cmake version 3.13.5
2)使用新版本cmake编译onnx-tensorrt
/path/to/cmake-3.13.5-Linux-x86_64/bin/cmake .. -DTENSORRT_ROOT=../../TensorRT-7.0.0.11
CMake Error at /xxx/cmake-3.13.5-Linux-x86_64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
/xxx/cmake-3.13.5-Linux-x86_64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/xxx/cmake-3.13.5-Linux-x86_64/share/cmake-3.13/Modules/FindProtobuf.cmake:595 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:80 (FIND_PACKAGE)
没有找到protobuf,一般是因为没有安装libprotobuf-dev
和 protobuf-compile
。
假如你的系统无法成功安装上面两个依赖,可以尝试以下方法:
# 下载官方protobuf
git clone https://github.com/protocolbuffers/protobuf.git
# 指定protobuf路径
cmake .. -DProtobuf_INCLUDE_DIR=/path/to/protobuf/src -DTENSORRT_ROOT=/path/to/TensorRT-7.0.0.11
-- Could NOT find TENSORRT (missing: TENSORRT_INCLUDE_DIR TENSORRT_LIBRARY)
ERRORCannot find TensorRT library.
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
没有找到TensorRT的lib和include,保证~/.bashrc
中已添加TensorRT
的环境变量以及onnx-tensorrt
与TensorRT
版本相匹配,理论上TensorRT 7.0.0.11
应使用onnx-tensorrt 7.0
分支。
cmake .. -DTENSORRT_ROOT=/path/to/TensorRT-7.0.0.11 -DCUDNN_INCLUDE_DIR=/home/work/cuda-10.0/include -DCUDNN_LIBRARY=/home/work/cuda-10.0/lib64
以上问题均类似,基本是缺XXX则编译时添加-DXXX=/path/to/XXX。
/usr/local/lib/libprotobuf.so: undefined reference to `memcpy@GLIBC_2.14'
/usr/local/lib/libprotobuf.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/usr/local/lib/libprotobuf.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/onnx2trt.dir/build.make:92: onnx2trt] Error 1
make[1]: *** [CMakeFiles/Makefile2:149: CMakeFiles/onnx2trt.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
可能是gcc
版本太低导致,可尝试切换至gcc 8.2
重新编译。
安装python库时出现以上错误,是由于缺少swig
库。
- Ubuntu安装swig
sudo apt-get install swig
- Centos安装swig
sudo yum install swig
building 'onnx_tensorrt.parser._nv_onnx_parser_bindings' extension
swigging nv_onnx_parser_bindings.i to nv_onnx_parser_bindings_wrap.cpp
swig -python -c++ -modern -builtin -o nv_onnx_parser_bindings_wrap.cpp nv_onnx_parser_bindings.i
NvOnnxParser.h:213: Error: Syntax error in input(1).
error: command 'swig' failed with exit status 1
在NvOnnxParser.h
头部添加#define TENSORRTAPI
# vim ./onnx-tensorrt/NvOnnxParser.h
# 添加如下内容
#define TENSORRTAPI
In file included from nv_onnx_parser_bindings_wrap.cpp:3529:
NvOnnxParser.h:28:10: fatal error: NvInfer.h: No such file or directory
#include "NvInfer.h"
^~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
未找到NvInfer.h
文件,同样的问题有NvInferVersion.h
,NvInferRuntime.h
,NvInferRuntimeCommon.h
。
解决办法:将TensorRT 7.0.0.11/include
下的同名文件copy到onnx-tensorrt文件夹下
cp /path/to/TensorRT 7.0.0.11/include/NvInfer* .
pip install onnx
10. error while loading shared libraries: libprotobuf.so.19: cannot open shared object file: No such file or directory
在执行./onnx2trt时报错如下:
./onnx2trt: error while loading shared libraries: libprotobuf.so.19: cannot open shared object file: No such file or directory
原因是没有找到libprotobuf.so.19
依赖文件。
解决方法:找到该文件并配至到环境变量中,如:
# vim ~/.bahsrc
export LD_LIBRARY_PATH=/path/to/protobuf/src/.libs:$LD_LIBRARY_PATH