下载protobuf-2.3.0:
    http://protobuf.googlecode.com/files/protobuf-2.3.0.zip

http://code.google.com/p/protobuf/downloads/list
安装: 
unzip protobuf-2.3.0.zip
cd protobuf-2.3.0
./configure
make 
make check 
make install

1.每步在执行过程中注意权限问题,有的命令不sudo执行会出问题。

./configure
make
make check
make install

2. 执行./configure 出现error,查看config.log文件看看是否缺某些安装软件,比如g++未安装等,因为执行文件中含有C++程序,所以出问题。

3.动静态库问题部分是转载

在Linux上编译google protobuff时,configure 默认选项是生成动态库,即libprotobuf.so文件。如果同时在多个动态库(动态库以dlopen方式动态加载)中使用同一buff结构,则运行时会报错误:

ibprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: foo/foo.proto libprotobuf FATAL google/protobuf/descriptor.cc:862] 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): 

为了解决这个问题,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文件,在把第2575至2578行修改为如下:

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"

需要注意的是不同版本的configure文件不同,所以源代码的行数也不同,2.3.0是1962行开始,贴出被替换代码,以便于替换

if test "x${ac_cv_env_CFLAGS_set}" = "x"; then
 CFLAGS=""
fi

if test "x${ac_cv_env_CXXFLAGS_set}" = "x"; then
  CXXFLAGS=""
fi
替换时注意if 和fi 的配对使用,否则执行不了,会出现语法错误,文件无法正常结束。

4.在修改文件后编译要重新编译,首先进行make clean ,否则不会重新执行。

5.最后修改环境变量,建议修改本用户的环境变量,~/.bashrc,不修改etc下环境变量

# append protobuf to PATH/lys
export PROTOBUF_HOME=/usr/local/protobuf/protobuf-2.3.0
export PATH=$PROTOBUF_HOME/bin:$PATH

HOME目录由安装目录而定,各不相同。

6.测试是否安装成功,protoc --version,显示出版本则说明安装成功

安装protobuf可能遇到的问题的更多相关文章

  1. MAC 安装 Protobuf

    1.确认MAC装有g++.make.vim工具 2.安装make工具使用       brew install make 3.安装protobuf brew install protobuf 4.安装 ...

  2. Linux下安装protobuf并实现简单的客户端服务器端通信

    http://code.google.com/p/protobuf/downloads/list上可以下载Protobuf的源代码. 安装步骤如下所示: 1>tar -xzf protobuf- ...

  3. mac 安装protobuf,并编译

    因公司接口协议是PB文件,需要将 PB 编译成JAVA文件,且MAC 电脑,故整理并分享MAC安装 google 下的protobuf 文件   MAC 安装protobuf 流程 1.下载 http ...

  4. linux下安装protobuf及cmake编译

    一.protobuf 安装 protobuf版本:2.6.1 下载地址:https://github.com/google/protobuf/archive/v2.6.1.zip 解压之后进入目录 修 ...

  5. Python3.6安装protobuf模块+将proto文件转换成pb2.py文件

    Python对版本的对应即为苛刻,笔者第一次安装时遇到了很多坑,比如无法将proto文件转换成py文件,转换了之后文件无法使用,网上各种各样的解决办法都没有讲到重点.其实会出现各种各样的问题是由于版本 ...

  6. 在 Ubuntu 上安装 Protobuf 3

    什么时候需要安装 如果使用 protoc 命令,遇到 Protoc not found,表示未安装.或者,执行时出现错误:This parser only recognizes "proto ...

  7. Win环境安装Protobuf 2.0 版本

    转载请注明出处: 安装步骤 下载 protobuf-2.5.0.zip 与 protoc-2.5.0-win32.zip 下载链接 : https://github.com/protocolbuffe ...

  8. centos 编译 安装 protobuf

    link:http://dbua.iteye.com/blog/1633079 yum -y install gcc+ gcc-c++ yum -y install make 下载protobuf-2 ...

  9. Centos6.5下安装protobuf及简单使用

    1.protobuf是google公司提出的数据存储格式,详细介绍可以参考:https://code.google.com/p/protobuf/ 2.下载最新的protobuf,下载地址:https ...

随机推荐

  1. restful的nginx配置方法

    location /{ root /webserver/www/a.tk.com; index index.html index.htm index.php; if ( $document_uri ~ ...

  2. float浮动的学习

    很早以前就接触过CSS,然后就在也没有深入了解过.今天突然遇到有人问了关系浮动的问题,碰巧没事就将内容整理下,与大家交流学习. 首先大家也应该都知道,div是块级元素,在页面中独占一行,自上而下排列, ...

  3. codeforces 449D DP+容斥

    Jzzhu and Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  4. app_data中的数据库使用

    原文发布时间为:2008-07-24 -- 来源于本人的百度文章 [由搬家工具导入] ASP.NET中利用VWD操作数据库 建立本地数据库   你可以轻易地在Visual Studio的Web应用程序 ...

  5. 转 markdown编写规则、语法

    http://www.jianshu.com/p/1e402922ee32/ Markdown——入门指南 字数2231 阅读307754 评论115 喜欢1350 转载请注明原作者,如果你觉得这篇文 ...

  6. Python日志(logging)模块使用方法简介

    A logger is configured to have a log level. This log level describes the severity of the messages th ...

  7. AC日记——dispatching bzoj 2809

    2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3290  Solved: 1740[Submi ...

  8. Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟

    原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...

  9. POJ 3660 Cow Contest 传递闭包+Floyd

    原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  10. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Minimization dp

    原题链接:http://codeforces.com/contest/572/problem/D 题意 给你个数组A和n,k,问你排列A后,下面的最小值是多少. 题解 先排个序,要填充像1,1+k,1 ...