解决TensorRT编译时protobuf模块编译错误

在编译TensorRT6.0的时候,可能会遇到protobuf下载导致的错误,
错误的issue:https://github.com/NVIDIA/TensorRT/issues/78
主要报错内容:

CMakeFiles/third_party.protobuf.dir/build.make:90: recipe for target 'third_party.protobuf/src/third_party.protobuf-stamp/third_party.protobuf-download' failed
make[2]: *** [third_party.protobuf/src/third_party.protobuf-stamp/third_party.protobuf-download] Error 1
CMakeFiles/Makefile2:139: recipe for target 'C
MakeFiles/third_party.protobuf.dir/all' failed

解决方法

issue上有一种解决方法是在编译cmake的时候加curl参数,我试过,没有解决我的问题。
查看报错内容,分析发现是是因为protobuf文件无法下载下来,于是根据报错内容,自己下载cmake的源码包,然后修改cmake文件,进行解决
修改的步骤如下:

1. 编译的时候,指定protobuf版本

在编译语句中,添加如下参数:

-DPROTOBUF_VERSION="3.11.4"

完整一点的

cmake .. -DTRT_LIB_DIR=$TRT_RELEASE/lib -DTRT_BIN_DIR=`pwd`/out  -DPROTOBUF_VERSION="3.11.4"

2.下载cmake源码

在执行完1中的命令后,执行下面的命令

cd hird_party.protobuf/src
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protobuf-cpp-3.11.4.tar.gz

如果你使用的是其他版本的protobuf,进行相应的修改,protobuf的下载地址在这里:https://github.com/protocolbuffers/protobuf/releases

3. 修改cmake

接上一步,执行下面的命令

vim third_party.protobuf-stamp/download-third_party.protobuf.cmake

在82行下添加

return()

也就是chek_file_hash()上面,和该行对其

4. 重新编译

先回到build目录下,然后执行

make -j$(nproc)

5.extract错误

如果在make的时候报extract的错误,那么就按照下面的步骤进行解决

  1. 解压protobuf
    如果已经解压了出现了protobuf1234的目录,那么就用这个
cp -rf protobuf1234/protobuf-3.11.4 third_party.protobuf

否则就自己解压

tar -zxvf protobuf-cpp-3.11.4.tar.gz -C third_party.protobuf
  1. 修改cmake文件
vim third_party.protobuf-stamp/extract-third_party.protobuf.cmake

在第一行加

return()

然后再次回到build目录进行make

make -j$(nproc)

我这边是没有再继续保持,编译成功过了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章