记录在 ubuntu 20.04 WSL 上安装的 golang protobuf
主要分为两部分:protobuf和protobuf-go的安装,主要参考链接:Protobuffers
1. protobuf
1.1 下载
这里使用了加速器下载,直接使用下方命令:
git clone https://github.com.cnpmjs.org/protocolbuffers/protobuf.git
1.2 安装
顺序执行下列命令:
sudo apt-get install dos2unix autoconf automake libtool curl make g++ unzip libffi-dev -y
进入/protobuf 目录后:
git submodule update --init --recursive (如果遇到下载不畅可修改该目录下.gitmodules文件,将所有子模块url改为 https://github.com.cnpmjs.org/ 开头,修改完毕后执行 git submodule sync, 最后再执行 update 命令)
dos2unix autogen.sh
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig
1.3 检查是否安装成功
执行: protoc -h 应该能正常显示命令帮助
2. golang-protobuf
2.1 下载
go get https://github.com/protocolbuffers/protobuf-go
2.2 安装
进入go安装目录$GOPATH,
cd $GOPATH/src/go/protobuf-go/cmd/protoc-gen-go
编译:
go build
将生成的可执行文件放入/bin目录
cp protoc-gen-go.exe /bin/