Installing Google Protocol Buffers on mac

2019-01-29 17:28发布

I would like to install the older version of Google Protocol Buffers (protobuf-2.4.1) on mac using Terminal command line. I tried with brew install protobuf, but the latest version 2.5.0 has been installed. Is it possible to install the older version from terminal.

Thanks

9条回答
手持菜刀,她持情操
2楼-- · 2019-01-29 18:07

From https://github.com/paulirish/homebrew-versions-1 . Works for me!

brew install https://raw.githubusercontent.com/paulirish/homebrew-versions-1/master/protobuf241.rb
查看更多
淡お忘
3楼-- · 2019-01-29 18:10

you can install from official link page provided by google http://google.github.io/proto-lens/installing-protoc.html

查看更多
Anthone
4楼-- · 2019-01-29 18:14

It's a new year and there's a new mismatch between the version of protobuf in Homebrew and the cutting edge release. As of February 2016, brew install protobuf will give you version 2.6.1.

If you want the 3.0 beta release instead, you can install it with:

brew install --devel protobuf
查看更多
Lonely孤独者°
5楼-- · 2019-01-29 18:16

There are some issues with building protobuf 2.4.1 from source on a Mac. There is a patch that also has to be applied. All this is contained within the homebrew protobuf241 formula, so I would advise using it.

To install protocol buffer version 2.4.1 type the following into a terminal:

brew tap homebrew/versions
brew install protobuf241

If you already have a protocol buffer version that you tried to install from source, you can type the following into a terminal to have the source code overwritten by the homebrew version:

brew link --force --overwrite protobuf241

Check that you now have the correct version installed by typing:

protoc --version

It should display 2.4.1

查看更多
倾城 Initia
6楼-- · 2019-01-29 18:19

This is not via brew, but the end result is the same.

  1. Download the protobuf-2.4.1 from https://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz
  2. Extract the tar.gz file.
  3. $cd ~/Downloads/protobuf-2.4.1
  4. $./configure
  5. $make
  6. $make check
  7. $sudo make install
  8. $which protoc
  9. $protoc --version

Steps 4-7 are from the README.txt file from the protobuf tarball.

查看更多
放荡不羁爱自由
7楼-- · 2019-01-29 18:20

For some reason I need to use protobuf 2.4.1 in my project on OS X El Capitan. However homebrew has removed protobuf241 from its formula. I install it according @kksensei's answer manually and have to fix some error during the process.

During the make process, I get 3 error like following:

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;

                           ^

(Sorry, I dont know how to attach code when the code contains '`' )

If you get the same error, please edit src/google/protobuf/message.cc, add #include <istream> at the top of the file and do $ make again and should get no errors. After that do $ sudo make install. When install finished $protoc --version should display the correct result.

查看更多
登录 后发表回答