下午在使用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 variable
和fatal error: google/protobuf/stubs/common.h: No such file or directory
这是因为我是直接下载了二进制的protobuf
,没有编译安装,缺少头文件。
其实protobuf
和grpc
的安装都比较麻烦,如果不嫌弃库的版本太老,推荐直接安装使用:
apt install libgrpc++-dev protobuf-compiler-grpc libprotobuf-dev
问题解决。
关于grpc
与protobuf
的安装和使用,参考这篇博客:grpc与protobuf最佳实践
文档信息
- 本文作者:last2win
- 本文链接:https://last2win.com/2020/03/01/grpc-error-2/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)