grpc C++笔记 - Go语言中文社区

grpc C++笔记


编译grpc C++教程

  • 点击download下载源代码(clone太慢) https://github.com/grpc/grpc
  • 点击逐个下载子模块,并复制到对应文件夹


    image.png
  • 准备cmake + Microsoft Visual c++编译器构建

Install Visual Studio 2015 or 2017 (Visual C++ compiler will be used).
Install Git.
Install CMake.
Install Active State Perl (choco install activeperl) - required by boringssl
Install Go (choco install golang) - required by boringssl
Install nasm and add it to PATH (choco install nasm) - required by boringssl
(Optional) Install Ninja (choco install ninja)

  • Windows, Using Visual Studio 2015 or 2017
mkdir .build
cd .build
cmake .. -G "Visual Studio 15 2017 Win64"
cmake --build . --config Debug

https://github.com/grpc/grpc/blob/master/BUILDING.md

搭建C++ rpc example(Windows)

  • 编译完成后,在VS2017中新建空的C++工程gRPCTest
  • 将helloworld.proto拷贝到工程目录下,将生成的protoc.exe拷贝到工程目录下
  • 打开cmd,运行以下命令
protoc.exe -I=. --grpc_out=. --plugin=protoc-gen-grpc=.grpc_cpp_plugin.exe helloworld.proto
protoc.exe -I=. --cpp_out=. helloworld.proto
// 注:protoc.exe版本要与之对应,不然会报错
此步驟會生出下面檔案
helloworld.pb.h
helloworld.pb.cc
helloworld.grpc.pb.h
helloworld.grpc.pb.cc
  • 拷贝grpc_cpp_plugin.exe,greeter_client.cc,greeter_server.cc至工程目录下
  • 选择Debug – x64构建配置


    image.png
  • 配置include目录、lib目录和lib导入


    image.png

    image.png

    image.png
  • lib目录
E:zdd-githubgrpc-master.buildthird_partyprotobufDebug;E:zdd-githubgrpc-master.buildDebug;E:zdd-githubgrpc-master.buildthird_partyzlibDebug;E:zdd-githubgrpc-master.buildthird_partycarescareslibDebug;E:zdd-githubgrpc-master.buildthird_partyboringsslDebug;E:zdd-githubgrpc-master.buildthird_partyboringsslsslDebug;E:Windows Kits10Lib10.0.18362.0umx64;E:zdd-githubgrpc-master.buildthird_partyboringsslcryptoDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslbaseDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslcontainerDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslflagsDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslhashDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslnumericDebug;
E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslrandomDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslstringsDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabslsynchronizationDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabsltimeDebug;E:zdd-githubgrpc-master.buildthird_partyabseil-cppabsltypesDebug;
  • lib导入
grpc++_unsecure.lib // 这个库必须放前面,不然解析不了ip
zlibd.lib;
ssl.lib
libprotobufd.lib
libprotobuf-lited.lib
libprotocd.lib
WS2_32.Lib
cares.lib;
upb.lib
boringssl_gtest.lib
grpcpp_channelz.lib
grpc_csharp_ext.lib
grpc++_reflection.lib
grpc++_error_details.lib
grpc_plugin_support.lib
grpc++_alts.lib
address_sorting.lib
grpc.lib
grpc++.lib;
grpc_unsecure.lib
zlibstaticd.lib
crypto.lib
gpr.lib
grpc_cronet.lib
absl_absl_base.lib
absl_absl_dynamic_annotations.lib
absl_absl_exponential_biased.lib
absl_absl_log_severity.lib
absl_absl_malloc_internal.lib
absl_absl_periodic_sampler.lib
absl_absl_raw_logging_internal.lib
absl_absl_scoped_set_env.lib
absl_absl_spinlock_wait.lib
absl_absl_throw_delegate.lib
absl_absl_hashtablez_sampler.lib
absl_absl_raw_hash_set.lib
absl_absl_flags.lib
absl_absl_flags_config.lib
absl_absl_flags_handle.lib
absl_absl_flags_internal.lib
absl_absl_flags_marshalling.lib
absl_absl_flags_program_name.lib
absl_absl_flags_parse.lib
absl_absl_flags_registry.lib
absl_absl_flags_usage.lib
absl_absl_flags_usage_internal.lib
absl_absl_city.lib
absl_absl_hash.lib
absl_absl_int128.lib
absl_absl_random_distributions.lib
absl_absl_random_internal_distribution_test_util.lib
absl_absl_random_internal_pool_urbg.lib
absl_absl_random_internal_randen.lib
absl_absl_random_internal_randen_hwaes.lib
absl_absl_random_internal_randen_hwaes_impl.lib
absl_absl_random_internal_randen_slow.lib
absl_absl_random_internal_seed_material.lib
absl_absl_random_seed_gen_exception.lib
absl_absl_random_seed_sequences.lib
absl_absl_str_format_internal.lib
absl_absl_strings.lib
absl_absl_strings_internal.lib
absl_absl_graphcycles_internal.lib
absl_absl_synchronization.lib
absl_absl_civil_time.lib
absl_absl_time.lib
absl_absl_time_zone.lib
absl_absl_bad_any_cast_impl.lib
absl_absl_bad_optional_access.lib
absl_absl_bad_variant_access.lib
  • 配置预处理器定义:_WIN32_WINNT=0x600


    image.png
  • 指定zlib(d).dll路径:PATH=E:zdd-githubgrpc-master.buildthird_partyzlibDebug;


    image.png
  • 客户端代码新增std::cin.get()避免窗口一闪而退

https://www.cnblogs.com/MakeView660/p/11511136.html
http://blog.alarmchang.com/?p=351
https://blog.csdn.net/qq_25005909/article/details/100540927

https://www.cnblogs.com/MakeView660/p/11511136.html
http://blog.alarmchang.com/?p=351

版权声明:本文来源简书,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.jianshu.com/p/7841c6bfccbf
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-02-02 14:53:13
  • 阅读 ( 1908 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢