花费了几个小时,终于搞定了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也是可以的,但是我还是向最小的影响系统环境。所以就采用静态链接的方式了。