安装过程比较麻烦,记录一下。

安装Protobuf

步骤如下:

1、下载源码:

GitHub源码地址:https://github.com/protocolbuffers/protobuf/releases

git clone –recursive https://github.com/protocolbuffers/protobuf.git

 

Gitee克隆地址:git clone https://gitee.com/tkxiong/protobuf.git

 

2、 安装Protobuf, 这里–prefix是设置安装目录

 

3、用户环境配置,修改profile文件

vim /etc/profile,或者 vim ~/.profile

添加环境变量:

保存执行,source /etc/profile;

4、 安装过程中可能出现的问题解决:

 

1. 可能会出现:

autogen这一步出现的依赖库的问题。

 

2. 可能会出现:

configure: WARNING: no configuration information is in third_party/googletest

需要下载googletest到 third_party/googletest 目录下,而且版本号最好是 1.8.1版本。主要是1.10版本我试了,就是不行。

https://github.com/google/googletest/releases

然后解压到googletest目录里面。

给出树形图,作为结构参考(可能文件没我的多,结构是对的就行)。

 

3. 如果Configure执行了两遍,也会导致make或者make install命令执行失败。

我的情况是搞错了安装目录,又重新执行了一次configure导致的。

解决办法是全部删掉重新拉取。

 

卸载:
人工删除,把以下文件夹及库文件删除即可
/usr/local/bin/protoc 执行文件
/usr/local/include/google 头文件
/usr/local/lib/libproto* (*表示可被任意字符替代) 库文件

 

参考文章:

https://www.cnblogs.com/coder-zyc/p/9504847.html

这一篇文章配置动态链接库我还没做,不知道有什么影响

 

https://blog.csdn.net/qq_34039018/article/details/88766816

这个就讲的比较详细一些。

 


安装 proto-gen-go

Protobuf安装完之后,因为是在go下面开发,使用protoc还需要安装 proto-gen-go

我试了修改GOPROXY还是没法正常go get,只能自己手动来了。(注意相对路径)

gitee地址:https://gitee.com/tkxiong/golang-protobuf

git clone https://gitee.com/tkxiong/golang-protobuf github.com/golang/protobuf

 

然后先安装 proto,再安装 protoc-gen-go。

go install github.com/golang/protobuf/proto

go install github.com/golang/protobuf/protoc-gen-go

 

如果有缺失的文件,就按之前的方法对应下载,可能会用到的github地址:

https://gitee.com/tkxiong/go-cmp

https://gitee.com/tkxiong/protobuf-go

将这两个分别下载到对应目录,然后再尝试就好。

 

需要添加环境变量:

export PATH=$PATH:$GOPATH/bin

 

 


 

记录一下使用出现的问题,这里我很奇怪 WARNING 说要设置 go_package,意思是现在不设置,以后的版本也会要求设置。

英文原文如下:

Packages

Source .proto files should contain a go_package option specifying the full Go import path for the file. If there is no go_package option, the compiler will try to guess at one. A future release of the compiler will make the go_package option a requirement. The Go package name of generated code will be the last path component of the go_package option.

翻译过来的意思是:

后缀 .proto文件应该包含 go_package 选项来指定完整的go导入路径。如果没有设置,编译器会尝试建议提供一个。未来的编译器会将go_package选择作为必要的。生成的代码的Go包名会是go_package选项的最后一个组件路径。

 

简单来讲,其实就是 Modules 化了。Go1.14版本之后就建议所有的包都使用Modules,这算是,与时俱进…

【Go】Ubuntu安装 Protobuf 和 proto-gen-go
Tagged on:     
0 0 投票数
Article Rating
订阅评论
提醒

0 评论
内联反馈
查看所有评论