linux安装protoc

下载安装包

下载地址

1、首先确定自己当前linux版本(当前版本为x86_64)

uname -a            

2、选择相应的版本下载并解压到当前目录

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip

unzip protoc-3.14.0-linux-x86_64.zip

3、安装 protoc

解压protoc压缩包后,可以看到 readme.txt文件

Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/

This package contains a precompiled binary version of the protocol buffer
compiler (protoc). This binary is intended for users who want touse Protocol
Buffers in languages other than C++ but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH.

If you intend touse the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.

Please refer to our official github site for more installation instructions:
  https://github.com/protocolbuffers/protobuf

大致意思是安装protoc,只需将bin目录下的二进制文件放在某个位置就行,如果你打算用其中的包含的其他类型,同时需要将include目录的内容也复制到某个地方,例如输入/usr/local/include/

我们把protoc放在/usr/local/bin可执行程序目录中,这样全局都可以访问到,同时把include目录的内容也复制到/usr/local/include/中

# 移动安装proto (cd到解压目录bin中后执行)mv proto /usr/local/bin

# 把`include`目录的内容复制(cd到解压目录include中后执行)cp google /usr/local/include
protoc --version
libprotoc 3.14.0

安装完成!

原文转自此篇文章https://www.cnblogs.com/niuben/p/14212878.html

1.下载和安装

 git clone https://github.com/protocolbuffers/protobuf.git

2、安装依赖库

$ cd protobuf/
$ ./autogen.sh
$ ./configure --prefix=/usr/local/protobuf
$ make
$ sudo make install
$ sudo ldconfig                  // 刷新共享库,很重要的一步

3、检查安装是否成功

$ protoc --version

1.环境配置

  1. 添加环境变量

sudo vim /etc/profile

添加:

export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

2、然后,刷新环境变量:

source /etc/profile

3、按照上述方式修改~/.profile。

4、配置动态链接库路径

sudo vim /etc/ld.so.conf

添加:

/usr/local/protobuf/lib

原文链接:https://blog.csdn.net/yahohi/article/details/108310609\

protobuf默认安装的时候,configure使用的是使用动态链接库的方式进行安装和使用的,在使用过程中,会报出这个错误:

[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: pro_projectasset.proto

[libprotobuf FATAL google/protobuf/descriptor.cc:1164] 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):

当时自己并没有搞清楚问题的根源。在网上看到是可以通过将protobuf链接的时候改成静态链接库的方式进行。后续跟进

这里先记录一下问题的解决方案:

方案一:

即是对protobuf重新编绎安装,步骤如下:

编译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:

./configure --disable-shared
make 
make install

编译完成后,使用libprotobuf.a文件

方案二:

make clean && make uninstall

注意看看是否已经删除了libprotobuf.a, libprotobuf.so

生成makefile的时候,配置命令:

./configure CXXFLAGS=-fPIC && make && make install

原文链接:https://blog.csdn.net/dreamvyps/article/details/73224627

  • 17
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值