protobuf linux 编译,linux下源码编译protobuf

本文详细介绍了在Linux环境下,如何通过configure和CMake两种方式编译安装protobuf,特别强调了CMake编译方式的优势和具体步骤。此外,还提供了一个简单的protobuf示例项目,展示了如何在CMakeLists.txt中配置protobuf,并解决运行时可能遇到的问题。
摘要由CSDN通过智能技术生成

linux下使用ProtoBuf, 有如下几种安装方式。

configure方式源码编译安装,发现使用的时候cmake找不到protobuf。

于是采用了 cmake 源码的安装方式。

1. 直接安装方式

安装: sudo apt-get install libprotobuf-dev protobuf-compiler

卸载: sudo apt-get remove libprotobuf-dev protobuf-compiler

2. configure方式源码编译安装

sudo apt-get install autoconf automake libtool curl make g++ unzip

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

cd protobuf

git submodule update --init --recursive

./autogen.sh

./configure --prefix=/usr/local/protobuf # 最好加上后面这个prefix,方便删除

make

make check

sudo make install

sudo ldconfig # refresh shared library cache.

设置环境变量

# (动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib

# (静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径

export LIBRAR

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值