记录protocol buffers Mac安装

使用brew安装最新的protobuf

在Mac 上安装,使用brew 可以安装最新的protobuf。这个也比较简单,简单说一下。

  1. 首先先检查一下是否安装了brew。如果没有安装brew的话,请先安装brew.可以通过brew --version来检查
  2. 使用brew install protobuf 来安装 protobuf
  3. 安装完成以后,可以使用protoc --version 来检查是否安装成功。如果正确输出了 版本号,则代表安装成功了。
  4. 如果想卸载的话,直接执行 brew uninstall protobuf 。如果在中途遇到了类似的错误,比如:
    Error: Refusing to uninstall /usr/local/Cellar/protobuf/23 because it is required by mysql@5.7 and sphinx, which are currently installed. You can override this and force removal with: brew uninstall --ignore-dependencies protobuf

因为protobuf依赖了mysql@5.7 和 sphinx 这两个库,所以你需要先卸载 这两个库,才能卸载protobuf。

你可以执行:

powershell 复制代码
brew uninstall sphinx

以及

powershell 复制代码
brew uninstall mysql@5.7

最后执行

powershell 复制代码
brew uninstall protobuf

然后就可以执行卸载了protobuf了。

安装指定版本的protobuf

使用上面的方式,只能安装最新版本的protobuf。如果想安装指定版本的protobuf的话,我们可以通过源码的方式进行安装。

  1. 先github上下载指定版本的源码 到本地。例如:3.21.12版本

将它下载到某个文件夹下。例如:我放在$HOME/programs/protobuf 。如果你本地没有这个文件夹的话,可以使用mkdir 命令去创建一个。

如果使用系统默认的安装目录的话,你可能遇到如下的错误:

powershell 复制代码
bcms436-sv1:protobuf-3.21.12 ytan$ make install
Making install in .
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/lib/pkgconfig" || ./install-sh -c -d "/usr/lib/pkgconfig"
 /usr/bin/install -c -m 644 protobuf.pc protobuf-lite.pc '/usr/lib/pkgconfig'
install: /usr/lib/pkgconfig/protobuf.pc: Permission denied
make[2]: *** [install-pkgconfigDATA] Error 71
make[1]: *** [install-am] Error 2
make: *** [install-recursive] Error 1
  1. $HOME/programs/protobuf 目录下,解压刚才下载的tar.gz文件
powershell 复制代码
tar -zxvf protobuf-3.21.12.tar.gz
  1. 进入到解压后的源码目录下:
powershell 复制代码
cd protobuf-3.21.12
  1. 检测安装环境是否满足条件,生成Makefile。注意使用如下目录
powershell 复制代码
./configure --prefix=$HOME/programs/protobuf

如果你在执行这个命令的后,发现有报错

powershell 复制代码
CXXLD libprotobuf.la
CXXLD libprotoc.la
CXXLD protoc
./.libs/libprotoc.so: error: undefined reference to 'xxxx'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:3990:protoc]

那么可以先执行./autogen.sh 命令,再执行 ./configure --prefix=$HOME/programs/protobuf

powershell 复制代码
./autogen.sh
  1. 编译和安装
powershell 复制代码
make && make install
  1. 添加环境变量

安装成功以后,就需要添加环境变量。添加环境变量时,需要注意你是使用的zsh,还是系统自带的命令行终端。

如果是系统的命令行终端:在系统根目录下找到.bash_profile 文件,在该文件下修改

powershell 复制代码
cd ~

vim .bash_profile
export PROTOBUF=$HOME/programs/protobuf
export PATH=$PROTOBUF/bin:$PATH
source .bash_profile

如果是zsh终端也是类似的,只是在 .zshrc 文件下修改。

powershell 复制代码
cd ~
vim .zshrc
export PROTOBUF=$HOME/programs/protobuf
export PATH=$PROTOBUF/bin:$PATH
source .
  1. 执行 protoc --version 验证

能正确输处版本号,就代表安装成功了。

相关推荐
2501_9159184122 分钟前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张41 分钟前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview
wjm0410061 小时前
ios面试八股文
ios·面试
FreeBuf_3 小时前
苹果用户速更新!macOS存严重漏洞,用户隐私数据面临泄露风险
macos
Thomas21433 小时前
macos deepctr_torch虚拟环境配置
macos
wxl7812273 小时前
MacOS 运行CosyVoice
macos·cosyvoice·语音自然
张较瘦_4 小时前
[论文阅读] 人工智能 + 软件工程 | 大模型破局跨平台测试!LLMRR让iOS/安卓/鸿蒙脚本无缝迁移
论文阅读·人工智能·ios
lichong9514 小时前
【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之video 的各种状态和生命周期调用说明
android·vue.js·macos
程序务虚论4 小时前
mac M1上安装windows虚拟机报错
windows·macos·parallels
今天头发还在吗7 小时前
【Go】:mac 环境下GoFrame安装开发工具 gf-cli——gf_darwin_arm64
macos·golang·go·gf-cli