google-protobuf安装详解

前言

编译调试项目的过程中涉及到caffe的编译,提示没有安装protobuf的错误,本文详解protobuf的安装;

问题描述

解决步骤

1.查看google protobuf的github,没有直接使用release而是对源码按照readme文件进行了编译;

protobuf需要一些依赖库,需要先进行安装;

$ sudo apt-get install autoconf automake libtool curl make g++ unzip

出现问题

注意,红框中的内容表示当前系统的sources.list中没有该库的源链接(目录在/etc/apt/sources.list),但并不表示当前系统没有安装该库;

不过,博主的当前系统的确是没有安装该库;

2.安装curl依赖库,参考here,不过最后的步骤改为以下命令则可正确安装;

sudo make install

 3. 按照protobuf的readme操作运行以下命令出错;

$ ./autogen.sh

错误如下

说明缺少gmock这个依赖库;

4.安装gmock依赖库,可参考here

5.安装之后按照readme的步骤进行编译即可;

$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.

注意,依赖库的版本需要与项目需要的版本一致,故注意依赖库的版本;

博主在解决这个问题的过程中编译完成的是当前protobuf的最新版本3.5.1,后来发现项目使用的是2.6.0或者2.6.1版本的;

 linux系统安装依赖库的方法

如何安装各种依赖库或者工具包;
1)直接使用apt-get install进行安装,这样能够正确安装的前提是系统中有源链接的文件,在/etc/apt/source.list文件中;
2)直接在github或者官网上找到包的源码,自己按照一定的步骤进行编译,需要注意的问题是版本是否一致;
3)一种是直接在相关网站上找到对应系统的包的release版本,使用sudo dpkg -I filename进行安装,

这个需要注意的是安装的包本身可能需要多个依赖项,需要将全部的依赖项都下载下来进行安装,

同时也需要注意包的版本是否匹配,另外,网站上的依赖包可能会有坏的,需要检查一下是否正确安装依赖项,

不能只查看文件,文件存在不一定正确安装,有可能只是一个空的链接,切记切记!!!!!

另外,我们使用的板子是ARM板子,故选择的包是arm64的,同时系统版本的codename是Xenial的,选择包的版本的时候需要注意。
使用lsb_release -a命令行可以查看系统的版本属性等;
一般含有箭头的文件可能就是某个链接,没有正确安装;

update20220307

安装onnx-tensorrt的时候出现could not find protobuf_include_dir的错误;

解决方法here and here

sudo apt-get install autoconf automake libtool curl make g++ unzip -y
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig

 查看protobuf版本

protoc --version

安装完成之后发现protobuf和tensorrt的版本不匹配,出错如下:

no matching function for call to 'google::protobuf::io::CodedInputStream::SetTotalBytesLimit(int)

原因:

因为protobuf新旧版本对SetTotalBytesLimit的定义不一样导致的问题
3.12.0之后的是一个形参
3.8.0之前是两个形参
中间的没试
用conda install protobuf==版本号安装所需版本

而目前系统protobuf版本是3.19.4,需要较早版本的protobuf,需要重新安装指定版本的protobuf

git clone -b v3.7.0 https://github.com/google/protobuf.git

 

 

 

参考

1.google protobuf github

2.依赖库curl的安装1

3.curl的安装-百度

4.IT大道-protobuf的安装

5.gmock-protobuf的安装

6. ubuntu系统Protobuf指定版本安装,以及报错解决方法

7. 解决no matching function for call to ‘google::protobuf::io::CodedInputStream::SetTotalBytesLimit(int)’

posted on 2018-02-13 14:43  鹅要长大  阅读(5103)  评论(0编辑  收藏  举报

导航