Sword protobuf学习一
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学习一的更多相关文章
- Sword protobuf学习四
#include <iostream> #include <string> #include <sys/types.h> /* See NOTES */ #incl ...
- Sword protobuf学习三
#include <iostream> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> ...
- Sword protobuf学习二
编写protobuf消息文件 文件格式: xxx.proto //标明使用哪个版本的protobuf,默认2.0版本 syntax = "proto3"; //类似于c++中的na ...
- google protobuf学习笔记:windows下环境配置
欢迎转载,转载请注明原文地址:http://blog.csdn.net/majianfei1023/article/details/45371743 protobuf的使用和原理,请查看:http:/ ...
- protobuf学习(2)-相关学习资料
protobuf官方git地址 protobuf官方英文文档 (你懂的需要FQ) protobuf中文翻译文档 protobuf概述 (官方翻译 推荐阅读) protobuf入门 ...
- 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 进入 ...
- Protobuf学习 - 入门
古之立大事者,不惟有超世之才,亦必有坚忍不拔之志 -- 苏轼·<晁错论> 从公司的项目源码中看到了这个东西,觉得挺好用的,写篇博客做下小总结.下面的操作以C++为编程语言,protoc的版 ...
- Protobuf学习 - 入门(转)
从公司的项目源码中看到了这个东西,觉得挺好用的,写篇博客做下小总结.下面的操作以C++为编程语言,protoc的版本为libprotoc 3.2.0. 一.Protobuf? 1. 是什么? Goo ...
- Protobuf学习
https://www.jianshu.com/p/2265f56805fa https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.ht ...
随机推荐
- 星云 Android 开发工具箱
Toast 工具类: SmartToastUtils.java import android.content.Context; import android.widget.Toast; /** * T ...
- DB2 格式化输出 Date
转自:http://www.cnblogs.com/zjun/archive/2012/02/15/2353054.html 在Oracle中可以使用TO_CHAR()函数来将日期类型的数据转换成字符 ...
- C语言发展历程及其保留字(关键字)——附:C语言标准文档
引言 抽时间对C语言发展历程和C语言的标准库文件及其保留字/关键字做了个梳理,后面附C语言各版本国际标准. C语言发展历程及其标准库 C语言关键字/保留字 C语言国际标准 ...
- std::bind技术内幕
引子 最近群里比较热闹,大家都在山寨c++11的std::bind,三位童孩分别实现了自己的bind,代码分别在这里: 木头云的实现 mr.li的实现 null的实现,null的另一个版本的实现 这些 ...
- wireshark抓取本地数据包
windows系统中,本地向自身发送数据包没有经过真实的网络接口,而是通过环路(loopback interface)接口发送,所以使用基于只能从真实网络接口中抓数据的winpcap是无法抓取本地数据 ...
- Tensorflow网址
https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/1-1-why/ 莫烦视频学习 http://wiki.jikex ...
- 获取windows可执行文件的version信息(版本号)
之前在msdn上Version Information看到文件版本信息的介绍,看着整体比较复杂,就一直没做.现在需要获取ocx文件的版本号,所以查找了下相关资料,比较有用的就是VS_FIXEDFILE ...
- DLL中获取主程序句柄
一.问题由来及说明 在实际编程中遇到一些系统模块(或API)调用初始化需要窗口句柄,在主程序中(MFC或者win32)都可以很容易获得,比如mfc中可以直接调用AfxGetMainWnd().GetS ...
- django模型查询
概述 查询集表示从数据库获取的对象的集合 查询集可以有多个过滤器 过滤器就是一个函数,基于所给的参数限制查询集结果 从SQL角度来说,查询集和select语句等价,过滤器就像where条件 查询集 在 ...
- jQuery之自定义datagrid控件
sldatagrid 效果: sldatagrid.js (function($) { function loadColumns(sldatagrid, columns) { $(sldatagrid ...