Mac安装protobuf 流程

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_21383435/article/details/81035852

1.brew安装protobuf

1.安装brew

ruby -e "$(curl -fsSL  https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.使用brew安装protoc

brew install protobuf

但是这安装的是最新版的

lcc@lcc ~$ protoc --version
libprotoc 3.6.0

1.1 安装指定版本

如果想安装指定版本该怎么办?

lcc@lcc ~$ brew uninstall protobuf
Uninstalling /usr/local/Cellar/protobuf/3.6.0... (256 files, 17.2MB)
lcc@lcc ~$ protoc --version
-bash: /usr/local/bin/protoc: No such file or directory

查看版本

lcc@lcc ~$ brew search protobuf
2018-07-14 15:32:00.305 defaults[13089:149521]
The domain/default pair of (kCFPreferencesAnyApplication, AppleLanguages) does not exist
==> Formulae
protobuf ✔                    protobuf-c                    protobuf-swift                protobuf@2.5                  protobuf@2.6                  protobuf@3.1                  swift-protobuf

安装指定版本

lcc@lcc ~$ brew reinstall protobuf@2.5
==> Reinstalling protobuf@2.5
==> Downloading https://homebrew.bintray.com/bottles/protobuf@2.5-2.5.0.high_sierra.bottle.tar.gz
Already downloaded: /Users/lcc/Library/Caches/Homebrew/protobuf@2.5-2.5.0.high_sierra.bottle.tar.gz
==> Pouring protobuf@2.5-2.5.0.high_sierra.bottle.tar.gz
==> Caveats
Editor support and examples have been installed to:
  /usr/local/opt/protobuf@2.5/share/doc/protobuf@2.5

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/protobuf@2.5/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/protobuf@2.5/lib
    CPPFLAGS: -I/usr/local/opt/protobuf@2.5/include

==> Summary
?  /usr/local/Cellar/protobuf@2.5/2.5.0: 79 files, 5.4MB
lcc@lcc ~$ protoc --version
-bash: /usr/local/bin/protoc: No such file or directory

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

lcc@lcc ~$ brew link --force --overwrite protobuf@2.5
Linking /usr/local/Cellar/protobuf@2.5/2.5.0... 14 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/protobuf@2.5/bin:$PATH"' >> ~/.bash_profile
lcc@lcc ~$ protoc --version
libprotoc 2.5.0
lcc@lcc ~$

2.编译安装

2.1 下载

https://github.com/google/protobuf/releases 找到对应版本下载

2.2 生成配置文件

下载自github的代码需要首先执行 $ ./autogen.sh 生成configure文件
注意autogen.sh 需要gtest包,默认是从 googletest.googlecode.com下载,国内需要翻墙才能访问,

cd protobuf
./autogen.sh

问题1
我执行这一步的时候总是报错

lcc@lcc protobuf-2.7.0$ ./autogen.sh
Google Mock not present.  Fetching gmock-1.7.0 from the web...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:01:15 --:--:--     0curl: (7) Failed to connect to googlemock.googlecode.com port 443: Operation timed out

翻墙都不行,最终用第一种方法安装成功

解决
参考: https://blog.csdn.net/xiexievv/article/details/47396725
修改一下autogen.sh
将这段:

echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
 curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
 mv gtest-1.5.0 gtest

修改为:

wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
tar xzvf release-1.5.0.tar.gz
mv googletest-release-1.5.0 gtest

再次执行

lcc@lcc protobuf-2.5.0$ ./autogen.sh
--2018-07-16 09:50:05--  https://github.com/google/googletest/archive/release-1.5.0.tar.gz
正在解析主机 github.com (github.com)... 52.74.223.119, 13.250.177.223, 13.229.188.59
正在连接 github.com (github.com)|52.74.223.119|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://codeload.github.com/google/googletest/tar.gz/release-1.5.0 [跟随至新的 URL]
--2018-07-16 09:50:07--  https://codeload.github.com/google/googletest/tar.gz/release-1.5.0
正在解析主机 codeload.github.com (codeload.github.com)... 13.229.189.0, 54.251.140.56, 13.250.162.133
正在连接 codeload.github.com (codeload.github.com)|13.229.189.0|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [application/x-gzip]
正在保存至: “release-1.5.0.tar.gz”

release-1.5.0.tar.gz                                    [                   <=>                                                                                            ] 412.67K  48.2KB/s  用时 8.6s

2018-07-16 09:50:19 (48.2 KB/s) - “release-1.5.0.tar.gz” 已保存 [422578]

x googletest-release-1.5.0/
x googletest-release-1.5.0/CHANGES

+ autoreconf -f -i -Wall,no-obsolete
./autogen.sh: line 41: autoreconf: command not found

问题2:autoreconf: command not found

解决

lcc@lcc protobuf-2.5.0$ brew install autoconf
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.high_sierra.bottle.4.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.high_sierra.bottle.4.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/autoconf
==> Summary
?  /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB

再次执行报错:

lcc@lcc protobuf-2.5.0$ ./autogen.sh
+ sed -i -e 's/RuntimeLibrary="5"/RuntimeLibrary="3"/g;
           s/RuntimeLibrary="4"/RuntimeLibrary="2"/g;' gtest/msvc/gtest-md.vcproj gtest/msvc/gtest.vcproj gtest/msvc/gtest_main-md.vcproj gtest/msvc/gtest_main.vcproj gtest/msvc/gtest_prod_test-md.vcproj gtest/msvc/gtest_prod_test.vcproj gtest/msvc/gtest_unittest-md.vcproj gtest/msvc/gtest_unittest.vcproj
+ autoreconf -f -i -Wall,no-obsolete
Can't exec "aclocal": No such file or directory at /usr/local/Cellar/autoconf/2.69/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
lcc@lcc protobuf-2.5.0$

详情 mac 系统下 autoconf 安装

未成功

2.3 配置

./configure
make

安装

make install

查看

protoc --version

Points

./autogen.sh是获取GoogleMock,并生成对应的configure脚本
./configure是进行环境检测,并生成对应的makefile或Makefile  --prefix=/usr/local可以指定安装路径
make,按照makefile编译工程
make install,执行makefile里面的install部分,进行安装       --prefix=/usr/local可以指定安装路径
展开阅读全文

没有更多推荐了,返回首页