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. [LeetCode] Paint House I & II

    Paint House There are a row of n houses, each house can be painted with one of the three colors: red ...

  2. 设计模式-观察者模式(Observer Pattern)

    观察者模式(Observer Pattern):定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使他们能够自动更新自己. 观察者 ...

  3. 帝国cms使用自定义函数获取新闻文章数 实例分享

    原文地址:http://www.jbxue.com/cms/24337.html 介绍了帝国cms系统中通过用户自定义函数获取用户发表新闻数量的方法,主要是分享下帝国cms自定义函数功能. 在帝国cm ...

  4. Atitit gui界面ui技术发展史与未来趋势

    Atitit gui界面ui技术发展史与未来趋势 1. Gui技术的发展,从像素自绘到native控件体系,再到dsl h51 1.1. 编程语言的发展 从机器语言,汇编语言到本地native语言(c ...

  5. 15个Spring的核心注释示例

    众所周知,Spring DI和Spring IOC是Spring Framework的核心概念.让我们从org.springframework.beans.factory.annotation和org ...

  6. HTTPS演变小图

    HTTP就是我们平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全.为了保证这些隐私数据能加密传输,网景公司设计了SSL(Se ...

  7. 【Socket】linux组播技术

    1.mystery引入      1)本学期学了计算机网络,对一些网络底层的东西还是不大了解    2)目前IP网络流行3种通信模式,分别是单播/广播与组播    3)根据Internet关于IP地址 ...

  8. 2015-07学习总结——网络编程(TCP/IP)

    之前学习的主要内容是单机上的处理,比如编程语言.游戏编程.数据库.多媒体编解码.其实对网络也有些接触,比如WWW.HTTP.UDP/TCP.RTP.RTMP.SNMP.FTP.单播组播.Telnet. ...

  9. Python如何下载文件

    转载自:http://www.codecho.com/how-to-download-a-file-in-python/ 利用程序自己编写下载文件挺有意思的.Python中最流行的方法就是通过Http ...

  10. 一个实体对象不能由多个 IEntityChangeTracker 实例引用。

    错误代码 public bool addSubOptionItem(csModel.cs_Answer answers) { bool result = false; wpe = new csWeiP ...