在mac上安装Google Protocol Buffers

inf*_*ker 96 homebrew protocol-buffers

我想使用终端命令行在mac上安装旧版本的Google Protocol Buffers(protobuf-2.4.1).我尝试过brew install protobuf,但已安装最新版本2.5.0.是否可以从终端安装旧版本.

谢谢

Joh*_*ore 143

在Mac上从源代码构建protobuf 2.4.1存在一些问题.还有一个补丁也必须应用.所有这些都包含在自制的protobuf241公式中,所以我建议使用它.

要安装协议缓冲区版本2.4.1,请在终端中键入以下内容:

brew tap homebrew/versions
brew install protobuf241
Run Code Online (Sandbox Code Playgroud)

如果您已经尝试从源安装协议缓冲区版本,则可以在终端中键入以下内容以使源代码被自制软件版本覆盖:

brew link --force --overwrite protobuf241
Run Code Online (Sandbox Code Playgroud)

通过键入以下内容检查您是否安装了正确的版本:

protoc --version
Run Code Online (Sandbox Code Playgroud)

它应该显示2.4.1

  • 不再工作了.我得到`警告:不推荐使用自制程序/版本.这个水龙头现在都是空的,因为它的所有公式都被迁移了 (13认同)
  • 那个水龙头不再可用了 (3认同)
  • 嘿,我试过这个,无论如何在protoc --version上我得到-bash:protoc:command not found (2认同)
  • 它已迁移到核心,请使用它:brew tap homebrew/homebrew-core (2认同)

小智 69

这不是通过brew,但最终结果是一样的.

  1. https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz下载protobuf-2.4.1
  2. 解压缩tar.gz文件.
  3. $ cd~/Downloads/protobuf-2.4.1
  4. $./配置
  5. $化妆
  6. $ make check
  7. $ sudo make install
  8. $ protoc
  9. $ protoc --version

步骤4-7来自protobuf tarball的README.txt文件.

  • 这对我有用,唯一的变化就是你需要从https://github.com/google/protobuf/releases下载资源 (4认同)
  • 我尝试了brew方法,但是对于最新版本的protobuf(现在是2.6.0),它可以使用上面的确切步骤从源代码轻松编译.当尝试扩展标准proto定义(例如,通过扩展descriptor.proto添加字段选项)时,这会变得更有用,因为您需要原始源或者必须引用home-brew安装版本中的Cellar路径(丑陋吗?) . (2认同)
  • 在运行make命令时,我最终遇到以下错误:3个错误。make [2]:*** [message.lo]错误1 make [1]:*** [所有递归]错误1 make:*** [all]错误2 (2认同)
  • 步骤 4-7 位于 `/protobuf/src/README.md`,我希望它位于 `/protobuf` 目录中的 `README.md` (2认同)

dan*_*nvk 34

这是新的一年,protobufHomebrew 版本和最新版本之间出现了新的不匹配.截至2016年2月,brew install protobuf将为您提供2.6.1版本.

如果您想要3.0 beta版本,可以使用以下命令安装:

brew install --devel protobuf
Run Code Online (Sandbox Code Playgroud)


小智 12

出于某种原因,我需要在我的OS X El Capitan项目中使用protobuf 2.4.1.然而,自制软件已从其公式中删除了protobuf241.我根据@kksensei的答案手动安装它,并且必须在此过程中修复一些错误.

在制作过程中,我得到3个错误如下:

google/protobuf/message.cc:130:60: error: implicit instantiation of undefined template 'std::__1::basic_istream<char, std::__1::char_traits<char> >'

  return ParseFromZeroCopyStream(&zero_copy_input) && input->eof();

                                                           ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:108:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_istream;

                           ^

google/protobuf/message.cc:135:67: error: implicit instantiation of undefined template 'std::__1::basic_istream<char, std::__1::char_traits<char> >'

  return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();

                                                                  ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:108:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_istream;

                           ^

google/protobuf/message.cc:175:16: error: implicit instantiation of undefined template 'std::__1::basic_ostream<char, std::__1::char_traits<char> >'

  return output->good();

               ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:110:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_ostream;

                           ^
Run Code Online (Sandbox Code Playgroud)

(对不起,当代码包含'''时,我不知道如何附加代码)

如果你得到同样的错误,请编辑src/google/protobuf/message.cc,#include <istream>在文件顶部添加并$ make再次执行,并且应该没有错误.之后呢$ sudo make install.安装完成后$protoc --version应显示正确的结果.

  • 这在 macOS Catalina 中对我有用!节省了我几个小时,谢谢! (2认同)

Van*_*Van 12

来自https://github.com/paulirish/homebrew-versions-1.适合我!

brew install https://raw.githubusercontent.com/paulirish/homebrew-versions-1/master/protobuf241.rb
Run Code Online (Sandbox Code Playgroud)


Roo*_*ahi 8

我用过macports

sudo port install protobuf-cpp
Run Code Online (Sandbox Code Playgroud)


小智 7

安装协议缓冲区(截至今天版本 v3.7.0)

  1. 去这个网站
  2. 根据您的操作系统下载 zip 文件(例如:protoc-3.7.0-osx-x86_64.zip)。这也适用于其他操作系统。

  3. 将 protoc-3/bin/protoc 中的可执行文件移动到 PATH 中的目录之一。在 Mac 中,我建议将其放入 /usr/local/bin

现在你可以走了

(可选)还有一个包含文件,可以添加。这是 README.md 的片段

If you intend to use the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.

Please refer to our official github site for more installation instructions:
https://github.com/protocolbuffers/protobuf
Run Code Online (Sandbox Code Playgroud)


Анд*_*чук 6

brew install --devel protobuf
Run Code Online (Sandbox Code Playgroud)

如果它告诉您“ protobuf-2.6.1已经安装”:1. brew uninstall --devel protobuf 2. brew link libtool 3。brew install --devel protobuf


Rev*_*kan 5

正如另一位用户提到的,谷歌还有另一种官方方式。

在尝试之前请完整阅读。

步骤如下:

打开终端并输入以下内容

  1. PROTOC_ZIP=protoc-3.7.1-osx-x86_64.zip
  2. curl -OL https://github.com/google/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
  3. sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
  4. rm -f $PROTOC_ZIP

为我工作。

PS
这仅适用于 osx 中的 3.7.1 版本。如果您想安装其他版本/平台,请访问版本链接并查看最新版本的详细信息,并使用这些信息。 参考

  • 又好又简单。谢谢!:田田: (2认同)

Adi*_*lli 5

这个过程简化为

brew install protobuf
Run Code Online (Sandbox Code Playgroud)

它会安装最新版本的protobuf。对我来说,在撰写本文时,它已经安装了v3.7.1

  • 但OP特别要求安装旧版本。 (2认同)