安装protobuf 流程 刺骨的言语ヽ痛彻心扉 2022-01-22 00:17 657阅读 0赞 1.brew安装protobuf 1.安装brew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 1 2.使用brew安装protoc brew install protobuf 1 但是这安装的是最新版的 lcc@lcc ~$ protoc --version libprotoc 3.6.0 1 2 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 1 2 3 4 查看版本 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 1 2 3 4 5 安装指定版本 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 如果您已经尝试从源安装协议缓冲区版本,则可以在终端中键入以下内容以使源代码被自制软件版本覆盖: 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 ~$ 1 2 3 4 5 6 7 8 2.编译安装 2.1 下载 https://github.com/google/protobuf/releases 找到对应版本下载 1 2.2 生成配置文件 下载自github的代码需要首先执行 $ ./autogen.sh 生成configure文件 注意autogen.sh 需要gtest包,默认是从 googletest.googlecode.com下载,国内需要翻墙才能访问, cd protobuf ./autogen.sh 1 2 问题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 1 2 3 4 5 翻墙都不行,最终用第一种方法安装成功 解决: 参考: 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 1 2 3 修改为: 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 1 2 3 再次执行 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 问题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 1 2 3 4 5 6 7 8 9 10 再次执行报错: 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$ 1 2 3 4 5 6 7 详情 mac 系统下 autoconf 安装 未成功 2.3 配置 ./configure make 1 2 安装 make install 1 查看 protoc --version 1 Points ./autogen.sh是获取GoogleMock,并生成对应的configure脚本 ./configure是进行环境检测,并生成对应的makefile或Makefile --prefix=/usr/local可以指定安装路径 make,按照makefile编译工程 make install,执行makefile里面的install部分,进行安装 --prefix=/usr/local可以指定安装路径
还没有评论,来说两句吧...