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-github\grpc-master\.build\third_party\protobuf\Debug;E:\zdd-github\grpc-master\.build\Debug;E:\zdd-github\grpc-master\.build\third_party\zlib\Debug;E:\zdd-github\grpc-master\.build\third_party\cares\cares\lib\Debug;E:\zdd-github\grpc-master\.build\third_party\boringssl\Debug;E:\zdd-github\grpc-master\.build\third_party\boringssl\ssl\Debug;E:\Windows Kits\10\Lib\10.0.18362.0\um\x64;E:\zdd-github\grpc-master\.build\third_party\boringssl\crypto\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\base\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\container\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\flags\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\hash\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\numeric\Debug;
E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\random\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\strings\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\synchronization\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\time\Debug;E:\zdd-github\grpc-master\.build\third_party\abseil-cpp\absl\types\Debug;
  • 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-github\grpc-master.build\third_party\zlib\Debug;


    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

你可能感兴趣的:(grpc C++笔记)