<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://itecfun.com/extern.php?action=feed&amp;tid=3367&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[个人知识管理站 / Centos 安装protobuf 3.6]]></title>
		<link>http://www.itecfun.com/viewtopic.php?id=3367</link>
		<description><![CDATA[Centos 安装protobuf 3.6 最近发表的帖子。]]></description>
		<lastBuildDate>Wed, 17 Oct 2018 01:32:23 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Centos 安装protobuf 3.6]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3633#p3633</link>
			<description><![CDATA[<p>protobuf是Google开发出来的一个语言无关、平台无关的数据序列化工具，在rpc或tcp通信等很多场景都可以使用。通俗来讲，如果客户端和服务端使用的是不同的语言，那么在服务端定义一个数据结构，通过protobuf转化为字节流，再传送到客户端解码，就可以得到对应的数据结构。这就是protobuf神奇的地方。并且，它的通信效率极高，“一条消息数据，用protobuf序列化后的大小是json的10分之一，xml格式的20分之一，是二进制序列化的10分之一”。</p><p>1、安装</p><p>编译安装protobuf的编译器protoc<br />wget <a href="https://github.com/protocolbuffers/protobuf/archive/v3.6.0.tar.gz" rel="nofollow">https://github.com/protocolbuffers/prot … 6.0.tar.gz</a></p><p>tar zxvf protobuf-3.6.0.tar.gz</p><p>cd protobuf-3.6.0</p><p>./autogen.sh #执行时出现错误</p><p>[root@master protobuf-3.6.0]# ./autogen.sh <br />+ autoreconf -f -i -Wall,no-obsolete<br />./autogen.sh: line 32: autoreconf: command not found</p><p>安装autoreconf,automake</p><p>yum -y install automake autoreconf</p><p>安装完成后，重新执行<br />./autogen.sh</p><p>出现错误</p><p>[root@master protobuf-3.6.0]# ./autogen.sh <br />+ autoreconf -f -i -Wall,no-obsolete<br />configure.ac:104: error: possibly undefined macro: AC_PROG_LIBTOOL<br />&#160; &#160; &#160; If this token and others are legitimate, please use m4_pattern_allow.<br />&#160; &#160; &#160; See the Autoconf documentation.<br />autoreconf: /usr/bin/autoconf failed with exit status: 1</p><p>这个错误的出现，还得安装libtool （为了保证不出错 ，还可安装一个工具：sudo apt-get install libsysfs-dev，这里没装也能成功）<br />yum install libtool</p><p>再次执行</p><p>./autogen.sh<br />执行成功，<br />目录下生成configure 文件</p><p>依次执行<br />./configure </p><p>make</p><p>make check</p><p>make install </p><p>安装完成后，Centos的系统默认安装目录为<br />/usr/local/bin<br />/usr/local/lib,<br />/usr/local/include </p><p>到这一步就可以使用protobuf了<br />$ protoc -I=./ --cpp_out=./ test.proto<br />到test.proto文件所在目录使用命令<br />protoc -I=./ --cpp_out=./ <br />生成C++版本的协议文件<br />一切OK的话，在当前目录看到.h和.cc文件</p><p>编译如果出现找不到符号和链接错误请记得加上链接选项 -lprotobuf <br />并确认你的静态库路径是否生效</p><p>$ echo $LIBRARY_PATH</p><br /><p><strong>附自定义安装：</strong></p><p>protobuf默认安装在 /usr/local 目录<br />你可以修改安装目录通过 ./configure --prefix=命令<br />虽然我是root用户但觉得默认安装过于分散，所以统一安装在/usr/local/protobuf下</p><p>$./configure --prefix=/usr/local/protobuf<br />$ make<br />$ make check<br />$ make install</p><p>到此步还没有安装完毕，在/etc/profile 或者用户目录 ~/.bash_profile<br />添加下面内容<br />####### add protobuf lib path ########<br />#(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径<br />export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib/<br />#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径<br />export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib/<br />#执行程序搜索路径<br />export PATH=$PATH:/usr/local/protobuf/bin/<br />#c程序头文件搜索路径<br />export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/protobuf/include/<br />#c++程序头文件搜索路径<br />export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/protobuf/include/<br />#pkg-config 路径<br />export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Wed, 17 Oct 2018 01:32:23 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3633#p3633</guid>
		</item>
	</channel>
</rss>
