如果使用C版本的gRPC,最终要从源码里编译出下列工具:
grpc_cpp_plugin
grpc_csharp_plugin
grpc_node_plugin
grpc_objective_c_plugin
grpc_php_plugin
grpc_python_plugin
grpc_ruby_plugin
git clone https://gitee.com/niubucai/grpc.git
cd grpc/
git tag
git checkout v1.12.0
执行一下步骤之前更换一下.gitmodule的内容
git submodule sync
git submodule update --init
make && make install
编译目录位于bins/opt下
.gitmodule替换内容
[submodule "third_party/zlib"]
path = third_party/zlib
url = https://gitee.com/niubucai/zlib.git
# When using CMake to build, the zlib submodule ends up with a
# generated file that makes Git consider the submodule dirty. This
# state can be ignored for day-to-day development on gRPC.
ignore = dirty
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://gitee.com/niubucai/protobuf.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://gitee.com/niubucai/googletest.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://gitee.com/niubucai/benchmark
[submodule "third_party/boringssl"]
path = third_party/boringssl
url = https://gitee.com/niubucai/boringssl.git
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url = https://gitee.com/niubucai/boringssl.git
[submodule "third_party/re2"]
path = third_party/re2
url = https://gitee.com/niubucai/re2.git
[submodule "third_party/cares/cares"]
path = third_party/cares/cares
url = https://gitee.com/niubucai/c-ares.git
branch = cares-1_12_0
[submodule "third_party/bloaty"]
path = third_party/bloaty
url = https://gitee.com/niubucai/bloaty.git
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://gitee.com/niubucai/abseil-cpp.git
branch = lts_2020_02_25
[submodule "third_party/envoy-api"]
path = third_party/envoy-api
url = https://gitee.com/niubucai/data-plane-api.git
[submodule "third_party/googleapis"]
path = third_party/googleapis
url = https://gitee.com/niubucai/googleapis.git
[submodule "third_party/protoc-gen-validate"]
path = third_party/protoc-gen-validate
url = https://gitee.com/niubucai/protoc-gen-validate.git
[submodule "third_party/udpa"]
path = third_party/udpa
url = https://gitee.com/niubucai/udpa.git
[submodule "third_party/libuv"]
path = third_party/libuv
url = https://gitee.com/niubucai/libuv.git
[submodule "third_party/opencensus-proto"]
path = third_party/opencensus-proto
url = https://gitee.com/niubucai/opencensus-proto.git
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://gitee.com/niubucai/gflags.git
通过hello.proto生成proto和grpc代码
./protobuf/bin/protoc -I . --cpp_out=. hello.proto
./protobuf/bin/protoc -I . --grpc_out=. --plugin=protoc-gen-grpc=./grpc/bins/opt/grpc_cpp_plugin hello.proto
暂时不知如何进行编译
g++ client.cc hello.grpc.pb.cc hello.pb.cc -I . -I protobuf/include/ -I grpc/include/ -L ./grpc/libs/opt/ -L/usr/local/lib -L ./grpc/libs/opt/protobuf -lgrpc++_reflection -lprotobuf -lpthread -lgrpc++ -lgrpc -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -ldl
/tmp/ccOvpXTz.o: In function `google::protobuf::io::CodedInputStream::SetTotalBytesLimit(int, int)':
hello.grpc.pb.cc:(.text._ZN6google8protobuf2io16CodedInputStream18SetTotalBytesLimitEii[_ZN6google8protobuf2io16CodedInputStream18SetTotalBytesLimitEii]+0x1f): undefined reference to `google::protobuf::io::CodedInputStream::SetTotalBytesLimit(int)'
/tmp/ccjoUmm2.o: In function `protobuf_hello_2eproto::protobuf_AssignDescriptors()':
hello.pb.cc:(.text+0x1f4): undefined reference to `google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
/tmp/ccjoUmm2.o: In function `google::protobuf::internal::InitSCC(google::protobuf::internal::SCCInfoBase*)':
hello.pb.cc:(.text._ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE[_ZN6google8protobuf8internal7InitSCCEPNS1_11SCCInfoBaseE]+0x4d): undefined reference to `google::protobuf::internal::InitSCCImpl(google::protobuf::internal::SCCInfoBase*)'
/tmp/ccjoUmm2.o: In function `google::protobuf::internal::OnShutdownDestroyMessage(void const*)':
hello.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x16): undefined reference to `google::protobuf::internal::DestroyMessage(void const*)'
hello.pb.cc:(.text._ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv[_ZN6google8protobuf8internal24OnShutdownDestroyMessageEPKv]+0x1e): undefined reference to `google::protobuf::internal::OnShutdownRun(void (*)(void const*), void const*)'
collect2: error: ld returned 1 exit status
代码见资料
参考:
https://www.cxyzjd.com/article/niu91/114995147