【protocolbuff】linux下安装google protobuf[实践] --未成功

参考:https://blog.csdn.net/xiexievv/article/details/47396725

说明:
protobuf已经全面迁移到github,地址:https://github.com/google/protobuf
直接下载2.6.1版本:https://github.com/google/protobuf/archive/v2.6.1.zip

默认安装:

$wget https://github.com/google/protobuf/archive/v2.6.1.zip
$unzip protobuf-2.6.1.zip
$cd protobuf-2.6.1

 下载自github的代码需要首先执行 $ ./autogen.sh 生成configure文件
注意autogen.sh 需要gtest包,默认是从 googletest.googlecode.com下载,国内需要翻墙才能访问,很多人问autogen.sh运行失败,这里我补充一下
修改一下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

再执行 autogen.sh,这样就不会报错了

(我这里还是会报错,因为的下下来的文件么有后缀名:release-1.5.0,所以我手工执行了

tar xzvf release-1.5.0.tar.gz
mv googletest-release-1.5.0 gtest

然后再重新执行autogen.sh 才通过)

$ ./configure 
$ make 
$ make check 
$ make install 
我使用的是centos系统 
/usr/local/bin 
/usr/local/lib, 
/usr/local/include 是也系统默认路径之一,所以到这一步就可以使用protobuf了 
$ protoc -I=./ --cpp_out=./ test.proto 
到你的test.proto文件所在目录使用命令
protoc -I=./ --cpp_out=./ 生成C++版本的协议文件 
一切OK的话,你回在当前目录看到.h和.cc文件

猜你喜欢

转载自blog.csdn.net/bandaoyu/article/details/88549426