protobuf简介
Protocol Buffers,是Google公司开发的一种数据描述语言,类似于XML能够将结构化数据序列化,可用于数据存储、通信协议等方面。
它不依赖于语言和平台并且可扩展性极强。现阶段官方支持C++、JAVA、Python三种编程语言,但可以找到大量的几乎涵盖所有语言的第三方拓展包。
#protobuf编译流程

.确定centos7上已经安装了下面的软件,或者直接用yum进行更新
autoconf
automake
libtool
curl (used to download gmock)
make
g++
unzip .下载源码包,解压,编译安装
地址:https://github.com/google/protobuf/releases
选择Source code (tar.gz)下载
>>tar -zxvf protobuf-3.1..tar.gz -C /usr/local/
>>cd protobuf-3.1./
>>./autogen.sh
# 指定安装路径
>>./configure --prefix=/usr/local/protobuf
#编译
>>make
# 测试,这一步很耗时间--不执行测试也无所谓
>>make check
>>make install .编写proto文件 .执行build.sh脚本,生成相关c文件 .业务逻辑编写
google protobuff动静态库问题

在Linux上编译google protobuff时,configure 默认选项是生成动态库,即libprotobuf.so文件。
如果程序以dlopen方式多次加载libprotobuf.so,并且使用的是同一个protobuff结构,则运行时将会报错
[libprotobuf ERROR google/protobuf/descriptor_database.cc:58] File already exists in database: google/protobuf/descriptor.proto
[libprotobuf FATAL google/protobuf/descriptor.cc:1394] CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): CHECK failed: generated_database_->Add(encoded_file_descriptor, size): Aborted (core dumped)
为了解决这个问题,google protobuff,则不能以动态库的形式调用,改用静态库的形式在编译时加载。
编译google protobuff时,在configure 时加上选项:
configrue --disable-shared
即可编译成静态库:libprotobuf.a 但是默认的configure文件中,在编译时未加-fPIC ,导致在引用静态库的工程中编译链接时报错误:
libs/assert.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; 
recompile with -fPIC .libs/assert.o: could not read symbols: Bad value
解决该问题,需要重新编译google protobuff库,并添加编译选项:-fPIC
以文本形式打开google buff代码目录下的configure文件,找到以下代码
if test "x${ac_cv_env_CFLAGS_set}" = "x"; then :
CFLAGS=""
fi
if test "x${ac_cv_env_CXXFLAGS_set}" = "x"; then :
CXXFLAGS=""
fi
#添加编译选项:-fPIC
if test "x${ac_cv_env_CFLAGS_set}" = "x"; then :
CFLAGS="-fPIC"
fi
if test "x${ac_cv_env_CXXFLAGS_set}" = "x"; then :
CXXFLAGS="-fPIC"
fi
重新编译google protobuff

总结:google protobuff最好使用静态库

Sword protobuf学习一的更多相关文章

  1. Sword protobuf学习四

    #include <iostream> #include <string> #include <sys/types.h> /* See NOTES */ #incl ...

  2. Sword protobuf学习三

    #include <iostream> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> ...

  3. Sword protobuf学习二

    编写protobuf消息文件 文件格式: xxx.proto //标明使用哪个版本的protobuf,默认2.0版本 syntax = "proto3"; //类似于c++中的na ...

  4. google protobuf学习笔记:windows下环境配置

    欢迎转载,转载请注明原文地址:http://blog.csdn.net/majianfei1023/article/details/45371743 protobuf的使用和原理,请查看:http:/ ...

  5. protobuf学习(2)-相关学习资料

    protobuf官方git地址 protobuf官方英文文档   (你懂的需要FQ) protobuf中文翻译文档 protobuf概述          (官方翻译 推荐阅读) protobuf入门 ...

  6. protobuf学习(1)-ubuntu14.04下protobuf2.6安装

    1 下载protobuf https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz 2  进入 ...

  7. Protobuf学习 - 入门

    古之立大事者,不惟有超世之才,亦必有坚忍不拔之志 -- 苏轼·<晁错论> 从公司的项目源码中看到了这个东西,觉得挺好用的,写篇博客做下小总结.下面的操作以C++为编程语言,protoc的版 ...

  8. Protobuf学习 - 入门(转)

    从公司的项目源码中看到了这个东西,觉得挺好用的,写篇博客做下小总结.下面的操作以C++为编程语言,protoc的版本为libprotoc 3.2.0. 一.Protobuf? 1. 是什么?  Goo ...

  9. Protobuf学习

    https://www.jianshu.com/p/2265f56805fa https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.ht ...

随机推荐

  1. 如何更新 Visual Studio 2017 的离线安装包

    现在 Visual Studio 2017 已经不再使用原来的 iso 镜像提供离线安装包了,需要的话,可以通过命令行参数下载离线安装包,例如: vs_Enterprise.exe --layout ...

  2. C#-微信公众平台接口-上传临时素材

    最烦做微信公众平台的东西..文档说得不清不楚,又没示例代码,只能自己 慢慢搜索,弄了一晚上,基本弄出来了,把本地的图片上传到微信的临时素材那里,返回媒体ID,用于其他操作,代码如下 :(自己导入相应的 ...

  3. ace admin后台模板

    http://ace.jeka.by/index.html 下载: http://www.daimajiayuan.com/plus/download.php?open=0&aid=18152 ...

  4. xcode代码没颜色的解决方案

    转自:http://blog.csdn.net/jiarusun000/article/details/7527631 今天代码使用了svn后发现项目中的所有原文件都没颜色了... 查找半天后发现是因 ...

  5. extern C的作用具体解释

    转载于:http://www.cnblogs.com/rollenholt/archive/2012/03/20/2409046.html 1.引言 C++语言的创建初衷是"a better ...

  6. linux关闭selinux和firewall

    sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config setenforce 0

  7. mongoose更新文档的时候让某个字段自增

    Station.update({ _id: req.params.id }, { $set: req.body, $inc: { count: 1 } }, { multi: false }, cal ...

  8. CCDictionary

    /** * CCDictionary is a class like NSDictionary in Obj-C . * * @note Only the pointer of CCObject or ...

  9. Python处理大数据

    起因 Python处理一下数据,大概有六七个G,然后再存到另外一个文件中,单线程跑起来发现太慢了,数据总量大概是千万行的级别,然后每秒钟只能处理不到20行--遂想怎么提高一下速度 尝试1-multip ...

  10. FFmpeg Basic学习笔记(3)

    视频叠加--画中画效果 overlay video filter 视频叠加比较常见的应用场景是台标的叠加,在画面左上角.右上角.左下角或右下角叠加台标. ffmpeg提供的overlay filter ...