因为项目中的protobuf是2.5.0版本,但是旧版本的protobuf 不支持M1,此时需要修改源码重新编译
操作步骤:
- 从git上面下载对应版本的protobuf,地址:Release Protocol Buffers v2.5.0 · protocolbuffers/protobuf · GitHub
- 解压进入src/google/protobuf/stubs/这个目录下,编辑platform_macros.h
- 找到以下代码
#else
#error Host architecture was not detected as supported by protobuf
- 在上面增加
#elif defined(__arm64__)
#define GOOGLE_PROTOBUF_ARCH_ARM 1
#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
最终结果如下图
- 在源码根目录下执行(****/protobuf-2.5.0/)
./configure
make
make check
make install
- 验证
执行下面检查protoc命令是否存在
which protoc
注意事项
下载红框里的tag版本后重新编译,不是下载source code哦
参考链接
附 brew 安装 protobuf 2.5.0
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/0f0b2fc5e2541712b0bb06f74cc1559b1c884750/Formula/protobuf@2.5.rb
作者:tison
链接:https://www.zhihu.com/question/360006055/answer/928011185
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。