Ubuntu下grpc的费时费力的编译方法
flyfish
按照官网教程,文件下载不了
为了方便,将grpc所需文件以上传
下载地址
进行以下操作
手工下载 所需的第三方文件
第三方文件夹在 grpc/third_party
把下载的源码放到third_party中各自的目录
下载grpc依赖库:
github上的文件以zip的方式下载
https://github.com/google/benchmark/archive/master.zip
benchmark-master.zip
https://github.com/gflags/gflags/archive/master.zip
gflags-master.zip
https://github.com/google/googletest/archive/master.zip
googletest-master.zip
https://github.com/google/protobuf/archive/master.zip
protobuf-master.zip
https://github.com/apache/thrift/archive/master.zip
thrift-master.zip
https://github.com/madler/zlib/archive/master.zip”
zlib-master.zip
c-ares-1.12.0.tar.gz
编译grpc前需要先编译cares(c-ares-1.14.0.tar.gz)和protobuf
源代码拷贝到grpc/third_party/cares/cares路径下
cares的编译安装
进入cares目录
./configure
make
make install
如果不按照上述说明安装
会出现
Package libcares was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcares.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libcares', required by 'grpc', not found
protobuf的编译安装
./configure
make
sudo make install
grpc的编译安装
make
make install
最后需要编译运行helloworld程序验证一下
编译方法是直接make
lib/grpc/examples/cpp/helloworld$ make
编译目录在grpc/examples/cpp/helloworld
如果出现下列提示 把grpc/examples/cpp/helloworld
helloworld.pb.h和helloworld.pb.cc删除下次编译会自动生成
g++ -std=c++11 `pkg-config --cflags protobuf grpc` -c -o helloworld.pb.o helloworld.pb.cc
In file included from helloworld.pb.cc:5:0:
helloworld.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
helloworld.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
helloworld.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
最后成功提示如下
服务器
运行
grpc/examples/cpp/helloworld$ ./greeter_server
提示
Server listening on 0.0.0.0:50051
客户端
运行
grpc/examples/cpp/helloworld$ ./greeter_client
提示
Greeter received: Hello world