protobuf安装与环境配置
本文记录的是用于GoLang项目的protobuf相关安装与环境配置,由于踩了些坑,所以记录一下。
- GoLang版本:1.17.6 linux/amd64
- 操作系统:Linux Mint 20.3 Cinnamon
安装 protobuf
# 在任意位置下载 protobuf 源文件包
cd /tmp/
git clone --depth=1 https://github.com/protocolbuffers/protobuf
# 解压之后进入
cd protobuf
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
# 查看 protoc 版本,成功输出版本号,说明安装成功
protoc --version
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
安装 protoc-gen-go
go install github.com/golang/protobuf/protoc-gen-go
1
可能存在的问题
autoreconf: not found
【Q】具体问题
./autogen.sh: 4: autoreconf: not found
【A】解决方案
sudo apt-get install autoconf automake libtool
1
error: C++ preprocessor
【Q】具体问题
checking how to run the C++ preprocessor… /lib/cpp
configure: error: in/home/wind/Wind/apps/common/protobuf': configure: error: C++ preprocessor "/lib/cpp" fails sanity check See
config.log’ for more details
【A】解决方案
sudo apt-get install g++
1
no configuration information is in third_party/googletest
【Q】具体问题
configure: WARNING: no configuration information is in third_party/googletest
【A】解决方案
执行如下命令,可以检测并补全third_party
目录下所有文件,包括但不限于googletest
,是最简单的方式:
git submodule update --init --recursive
1
2
2
也可以直接通过如下完成:
- 从 https://github.com/google/googletest/releases 获取源文件
- 如 https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz
- 解压并重命名为
googletest
(即去掉文件夹中的版本号),并放到third_party/
即可。
libprotoc.so.30: cannot open shared object file: No such file or directory
【Q】具体问题
protoc: error while loading shared libraries: libprotoc.so.30: cannot open shared object file: No such file or directory
【A】解决方案
方案一: 最简单的方式是在/etc/profile
或 .bashrc
等相关文件中加入: export LD_LIBRARY_PATH=/usr/local/lib
,如:
# vim /etc/profile
# 文件最下面添加:
export LD_LIBRARY_PATH=/usr/local/lib
# source /etc/profile
1
2
3
4
2
3
4
方案二: 但使用过程中发现仅当次有效,注销系统后又失效了,故采用了如下方式:
- 通过
sudo vim /etc/ld.so.conf.d/libprotobuf.conf
新建【/etc/ld.so.conf.d/libprotobuf.conf】 ,内容如下:/usr/local/lib
1 - 执行命令
sudo ldconfig
/etc/profile
添加路径# vim /etc/profile export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH # source /etc/profile
1
2
3
参考资料
预览
除特别注明外,本站所有文章均为 windcoder 原创,转载请注明出处来自: protobufanzhuangyuhuanjingpeizhi
Loading comments...

预览
暂无数据