在Mac上从源代码构建protobuf 2.4.1存在一些问题。还需要应用补丁。所有内容都包含在homebrew protobuf241公式中,因此我建议使用它。
要安装协议缓冲区版本2.4.1,请在终端中输入以下内容:
brew tap homebrew/versions
brew install protobuf241
如果您已经有一个尝试从源代码安装的协议缓冲区版本,您可以在终端中键入以下内容,以便将源代码被Homebrew版本覆盖:
如果您已经安装了协议缓冲区的源代码版本,则可以在终端中输入以下命令,以使源代码被 Homebrew 版本覆盖:
brew link --force --overwrite protobuf241
通过输入以下命令,检查您是否已经安装了正确版本:
protoc --version
它应该显示 2.4.1
./protoc --version
- james.garrisscd ~/Downloads/protobuf-2.4.1
./configure
make
make check
sudo make install
which protoc
protoc --version
/protobuf/src/README.md
中,我希望它在/protobuf
目录下的README.md
中。 - Kevin Zhaobrew install protobuf
它会安装可用的最新版本的协议缓冲区。在我撰写本文时,这个命令安装了v3.7.1版本。
如果您想安装旧版本,请查看Protobuf Package - Homebrew包页面中提供的版本,并安装该特定版本的包。
此软件包中提供的最旧版本的protobuf是v3.6.1.3。
新的一年到了,Homebrew 中的 protobuf
版本与最新版本不匹配。截至 2016 年 2 月,brew install protobuf
将安装版本为 2.6.1。
如果您想安装 3.0 beta 版本,可以使用以下命令进行安装:
brew install --devel protobuf
从https://github.com/paulirish/homebrew-versions-1获取。对我来说有效!
brew install https://raw.githubusercontent.com/paulirish/homebrew-versions-1/master/protobuf241.rb
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;
^
如果您遇到相同的错误,请编辑src/google/protobuf/message.cc文件,在文件顶部添加#include <istream>
,然后再次运行$ make
。如果没有错误,则运行$ sudo make install
。安装完成后,$ protoc --version
应显示正确的结果。
sudo port install protobuf-cpp
根据你的操作系统下载zip文件(例如:protoc-3.7.0-osx-x86_64.zip)。其他操作系统也适用。
将可执行文件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
brew install --devel protobuf
如果它告诉你 "protobuf-2.6.1已经安装":
1. brew uninstall --devel protobuf
2. brew link libtool
3. brew install --devel protobuf
PROTOC_ZIP=protoc-3.7.1-osx-x86_64.zip
curl -OL https://github.com/google/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
rm -f $PROTOC_ZIP
.pb.h
和.pb.cc
文件,它们是向后兼容的。 - Kenton Varda