因为最近工作用到了protobuf,感兴趣的自己去百度一下这个东西是啥,怎么用的。放假期间,就自己先研究一下这个东西,所以本文就描述一下protobuf-c的环境搭建。
环境依赖以下三个工具,一般都会有没有安装一下就好了
autoconf automake libtool
源码安装也好,linux下的安装工具安装也行,都可以。
protobuf源码:
https://github.com/google/protobuf/releases/tag/v2.6.1
probuf-c源码:
https://github.com/protobuf-c/protobuf-c.git
因为protobuf是没有C语言支持的,所以找了个三方的C语言支持
先安装protobuf,安装包下载下来之后,解压,进入目录
./autogen.sh 生产配置文件configuer
./configure --prefix=/usr/local/protobuf --libdir=/usr/lib 检查配置环境并生产makefile
make 编译源码
make install 安装对应的库以及头文件
/sbin/ldconfig -v 动态库链接共享
以上我都是在root下执行的,若只是普通用户加sudo权限
然后就是安装protobuf-c,步奏是一样的。因为protobuf-c的安装依赖protobuf,所以要先装protobuf,否则在执行configure时就会在检查protobuf版本时出问题导致安装失败。
同样解压protobuf-c的压缩包,进入相应目录
./autogen.sh 生产配置文件configuer
./configure --prefix=/usr/local/protobuf-c --libdir=/usr/lib/ 检查配置环境并生产makefile
make 编译源码
make install 安装
sudo cp -r /usr/local/protobuf-c/include/protobuf-c /usr/include 拷贝头文件
因为protobf-c的安装不会自动将头文件拷贝过去,后面我们测试的时候会有麻烦,所以这里手动拷贝。
以上就完成了protobuf 以及protobuf对C语言支持环境的安装了。
安装完成之后
就可以看到刚才安装目录下的库文件,以及protoc工具了protoc-c是protoc-gen-c的链接。至于怎么使用,我们后面再说。