grpc与protobuf 报错解决:Perhaps you should add the directory containing `protobuf.pc' to the PKG_CONFIG_PATH environment variable

此文首发于我的Jekyll博客:zhang0peter的个人博客


下午在使用grpc的时候遇到了报错:

-> # make
g++ -std=c++11 `pkg-config --cflags protobuf grpc`  -c -o helloworld.pb.o helloworld.pb.cc
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
In file included from helloworld.pb.cc:5:0:
helloworld.pb.h:9:10: fatal error: google/protobuf/stubs/common.h: No such file or directory
 #include <google/protobuf/stubs/common.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'helloworld.pb.o' failed
make: *** [helloworld.pb.o] Error 1

里面提到了报错Perhaps you should add the directory containing protobuf.pc' to the PKG_CONFIG_PATH environment variablefatal error: google/protobuf/stubs/common.h: No such file or directory

这是因为我是直接下载了二进制的protobuf,没有编译安装,缺少头文件。

其实protobufgrpc的安装都比较麻烦,如果不嫌弃库的版本太老,推荐直接安装使用:

apt install libgrpc++-dev protobuf-compiler-grpc libprotobuf-dev 

问题解决。


关于grpcprotobuf的安装和使用,参考这篇博客:grpc与protobuf最佳实践