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 ...
随机推荐
- 配置ssh的config文件-为每个ssh连接创建别名
其实选来选去,还是iterm2就够用了,唯一比较麻烦的就是每次都有输入地址和用户名,其实,可以通过配置文件简写的. 可以在 ~/.ssh/config文件写上配置alias信息,以后ssh的时候根据a ...
- spring(四) 手动整合web项目(SSH)
清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...
- 【Unity】3.4 将现有的3ds Max模型导入到Unity
分类:Unity.C#.VS2015 创建日期:2016-04-05 一.简介 这一节我们用一个带有"装子弹和上膛"动画的"枪"模型,介绍在3ds Max 20 ...
- U盘启动ubuntu 12.04
第一步: 下载U盘启动制作工具Universal-USB-Installer-1.9.5.9.exe http://www.pendrivelinux.com/downloads/Universal- ...
- placement new (转)
原文出自:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 1. placement new的含义placement n ...
- close Spark Streaming gratefully
https://blog.csdn.net/u010454030/article/details/78679930 https://blog.csdn.net/u010454030/article/d ...
- [DIOCP3-说明书] 关于DEMO的编译
总有些朋友问我,关于DEMO编译的一些问题,每次都回答大概都差不多,我想还是写篇说明书给大家,关于DEMO编译的步骤. [环境设定] 1.将DIOCP3\source路径添加到Delphi的搜索路 ...
- 【Socket】linux网络多路复用IO技术
1.mystery引入 1)Select是一种多路复用IO输入输出模式,在linux的输入输出编程中通过select的轮询机制,发现可用/可读或可写的接口. 2)低级socket程 ...
- Pandas Dataframe增、删、改、查、去重、抽样基本操作
总括 pandas的索引函数主要有三种: loc 标签索引,行和列的名称 iloc 整型索引(绝对位置索引),绝对意义上的几行几列,起始索引为0 ix 是 iloc 和 loc的合体 at是loc的快 ...
- 1. 感知机原理(Perceptron)
1. 感知机原理(Perceptron) 2. 感知机(Perceptron)基本形式和对偶形式实现 3. 支持向量机(SVM)拉格朗日对偶性(KKT) 4. 支持向量机(SVM)原理 5. 支持向量 ...