我想使用命令行/终端应用程序在Mac上安装旧版本的Google Protocol Buffers(protobuf-2.4.1)。
我尝试了brew install protobuf
,但已安装最新版本 2.5.0。
是否可以从终端安装旧版本?
在Mac上从源代码构建protobuf 2.4.1存在一些问题。还有一个补丁也必须应用。所有这些都包含在自制的protobuf241公式中,所以我建议使用它。
要安装协议缓冲区版本 2.4.1,请在终端中键入以下内容:
brew tap homebrew/versions
brew install protobuf241
如果您已经有一个尝试从源代码安装的协议缓冲区版本,则可以在终端中键入以下内容,以使源代码被自制版本覆盖:
brew link --force --overwrite protobuf241
通过键入以下内容检查您现在是否安装了正确的版本:
protoc --version
它应该显示 2.4.1
这不是通过酿造,但最终结果是相同的。
- 从 https://github.com/protocolbuffers/protobuf/releases/tag/v2.4.1 下载 protobuf-2.4.1
- 解压缩 tar.gz 文件。
- $cd ~/下载/protobuf-2.4.1
- $./配置
- $make
- $make检查
- $sudo进行安装
- $which协议
- $protoc --版本
步骤 4-7 来自 protobuf 压缩包的 README.txt 文件。
如果您登陆此处寻找如何在Mac上安装Protocol Buffers,可以通过运行以下命令使用Homebrew来完成
brew install protobuf
它安装了最新版本的protobuf。对我来说,在撰写本文时,这安装了 v3.7.1
如果您想安装旧版本,请从软件包页面 Protobuf 包 - 自制软件中查找可用的版本并安装该特定版本的软件包。
此软件包中最古老的可用 protobuf 版本是 v3.6.1.3
这是新的一年,Homebrew 中的 protobuf
版本与尖端版本之间存在新的不匹配。截至2016年2月,brew install protobuf
将为您提供2.6.1版本。
如果您想要 3.0 测试版,您可以使用以下命令安装它:
brew install --devel protobuf
出于某种原因,我需要在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;
^
(抱歉,当代码包含"时,我不知道如何附加代码)
如果您收到相同的错误,请编辑src/google/protobuf/message.cc,在文件顶部添加#include <istream>
并再次执行$ make
,应该不会出错。之后做$ sudo make install
.安装完成后$protoc --version
应显示正确的结果。
来自 https://github.com/paulirish/homebrew-versions-1 .对我有用!
brew install https://raw.githubusercontent.com/paulirish/homebrew-versions-1/master/protobuf241.rb
我用了macports
sudo port install protobuf-cpp
安装协议缓冲区(从今天版本 v3.7.0 开始)
- 转到此网站
-
根据您的操作系统下载 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
为我工作。
附言这仅适用于 osx 中的版本 3.7.1。如果要安装其他版本/平台,请访问发布链接并查看最新版本的详细信息,并使用这些信息。参考
FWIW.,最新版本的brew是protobuf 3.0,不包含旧版本的任何公式。这有点"不方便"。
虽然 protobuf 可能在线线级别兼容,但它在生成的 java 类级别绝对不兼容:您不能将 protoc 2.4 生成的.class文件与 protobuf-2.5 JAR 等一起使用。这就是为什么更新protobuf版本在Hadoop堆栈中是一个如此敏感的话题:它总是需要不同项目之间的协调,并且足够痛苦,以至于没有人喜欢这样做。
HomeBrew 版本已被删除,公式已被清空。因此,我的建议是按照以下步骤手动安装它。
目前,您需要手动构建和安装协议缓冲区工具集。
-
下载源代码:https://github.com/google/protobuf/releases/download/v2.4.1/protobuf-2.4.1.tar.gz
-
tar xvfz protobuf-2.4.1.tar.gz
-
cd protobuf-2.4.1
-
运行
./configure
-
编辑 src/google/protobuf/message.cc,在文件顶部添加 #include
-
从文件夹的根目录运行
make
命令,即 protobuf-2.4.1/ -
运行
sudo make install
-
运行
/usr/local/bin/protoc --version
以检查 protobuf 编译器版本的版本终端输出应为:Version: libprotoc 2.4.1
您可以从谷歌提供的官方链接页面安装 http://google.github.io/proto-lens/installing-protoc.html
适用于 v3 用户。
http://google.github.io/proto-lens/installing-protoc.html
PROTOC_ZIP=protoc-3.7.1-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
应该有更好的方法,但我今天所做的是:
-
从 https://github.com/protocolbuffers/protobuf/releases 下载(目前
protoc-3.14.0-osx-x86_64.zip
) -
解压缩(双击
zip
文件) -
在这里,我添加了一个符号链接
ln -s ~/Downloads/protoc-3.14.0-osx-x86_64/bin/protoc /usr/local/bin/protoc
- 检查是否有效
protoc --version
<</div>
div class="one_answers"> 下面的链接清楚地说明了如何在Macbook中安装特定版本的protobuf。
https://makeoptim.com/en/tool/brew-install-specific-version/