protobuf 中 examples的编译 cpp和python

花费了几个小时,终于搞定了protobuf中examples的编译,只有cpp和python模块。
下载protobuf的代码后,执行了protobuf的安装,然后进入examples的目录。


make python还好,只要安装了protobuf中的python内容就可以了,但是make cpp的修改就费了一番周折。
执行make cpp后,显示报这个错误:

protoc --cpp_out=. --java_out=. --python_out=. addressbook.proto
pkg-config --cflags protobuf  # fails if protobuf is not installed
Package protobuf was not found in the pkg-config search path.
Perhaps you should add the directory containing `protobuf.pc'
to the PKG_CONFIG_PATH environment variable
No package 'protobuf' found


发现没有设置PKG_CONFIG_PATH,于是设置一下:
export PKG_CONFIG_PATH=/home/install_protobuf_path/lib/pkgconfig/


  
然后执行make cpp成功,但是因为我的安装路径不是用的默认的,而是自己的一个目录,导致找不到动态库libprotobuf.so.8。
只好把编译条件改为静态链接.a文件,这样才ok了。
protoc --cpp_out=. addressbook.proto
c++ add_person.cc addressbook.pb.cc -o add_person_cpp -pthread -I/home/install_protobuf_path/include -pthread -L/home/install_protobuf_path/lib -static -lprotobuf -lpthread
c++ list_people.cc addressbook.pb.cc -o add_person_cpp -pthread -I/home/install_protobuf_path/include -pthread -L/home/install_protobuf_path/lib -static -lprotobuf -lpthread  

如果将so放在系统指定的lib目录下当然最好,可是因为我要修改protobuf,所以不想直接放到系统目录下,修改环境变量LD_LIBRARY_PATH也是可以的,但是我还是向最小的影响系统环境。所以就采用静态链接的方式了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值