一、环境构建

1. CMake

Download CMake

2. Git

Git for Windows

3. gRPC源码

1
git clone -b v1.48.0 https://github.com/grpc/grpc

进入源码目录

1
cd grpc

下载依赖库

1
git submodule update --init

二、使用CMake生成工程文件

三、使用vs2019编译grpc库文件

四、使用vs2019编译grpc库文件

将库文件和头文件提取出来放入include和lib

头文件需要

还有absl,grpc-1.4.8\grpc\third_party\protobuf\src

库文件需要的有下面这些

absl_bad_optional_access.lib

absl_bad_variant_access.lib

absl_base.lib

absl_city.lib

absl_civil_time.lib

absl_cord.lib

absl_cordz_functions.lib

absl_cordz_handle.lib

absl_cordz_info.lib

absl_cordz_sample_token.lib

absl_cord_internal.lib

absl_debugging_internal.lib

absl_demangle_internal.lib

absl_examine_stack.lib

absl_exponential_biased.lib

absl_failure_signal_handler.lib

absl_flags.lib

absl_flags_commandlineflag.lib

absl_flags_commandlineflag_internal.lib

absl_flags_config.lib

absl_flags_internal.lib

absl_flags_marshalling.lib

absl_flags_parse.lib

absl_flags_private_handle_accessor.lib

absl_flags_program_name.lib

absl_flags_reflection.lib

absl_flags_usage.lib

absl_flags_usage_internal.lib

absl_graphcycles_internal.lib

absl_hash.lib

absl_hashtablez_sampler.lib

absl_int128.lib

absl_leak_check.lib

absl_log_severity.lib

absl_low_level_hash.lib

absl_malloc_internal.lib

absl_periodic_sampler.lib

absl_random_distributions.lib

absl_random_internal_distribution_test_util.lib

absl_random_internal_platform.lib

absl_random_internal_pool_urbg.lib

absl_random_internal_randen.lib

absl_random_internal_randen_hwaes.lib

absl_random_internal_randen_hwaes_impl.lib

absl_random_internal_randen_slow.lib

absl_random_internal_seed_material.lib

absl_random_seed_gen_exception.lib

absl_random_seed_sequences.lib

absl_raw_hash_set.lib

absl_raw_logging_internal.lib

absl_scoped_set_env.lib

absl_spinlock_wait.lib

absl_stacktrace.lib

absl_status.lib

absl_statusor.lib

absl_strerror.lib

absl_strings.lib

absl_strings_internal.lib

absl_str_format_internal.lib

absl_symbolize.lib

absl_synchronization.lib

absl_throw_delegate.lib

absl_time.lib

absl_time_zone.lib

address_sorting.lib

cares.lib

crypto.lib

gpr.lib

grpc++.lib

grpc++_alts.lib

grpc++_error_details.lib

grpc++_reflection.lib

grpc++_unsecure.lib

grpc.lib

grpcpp_channelz.lib

grpc_plugin_support.lib

grpc_unsecure.lib

libprotobuf-lite.lib

libprotobuf.lib

libprotoc.lib

re2.lib

ssl.lib

upb.lib

zlib.lib

五、编译proto文件

注意:其中:grpc_cpp_plugin.exe所在路径替换为您安装的路径。

且proto路径根据自已的路径修改

1
2
protoc -I="./protos" --grpc_out="./protos" --plugin=protoc-gen-grpc="D:\workplace\grpc-1.4.8\grpc\cmake_build\Release\grpc_cpp_plugin.exe" "./protos\greet.proto"
protoc -I="./protos" --cpp_out="./protos" "./protos\greet.proto"

六、生成gprc客户端服务端

将生成的 .grpc.pb.cc/.h  .pb.cc/.h 以及proto文件添加到vs中,vs切换为Release x64版本(对应gRPC编译的版本,不知道Debug版本是否有问题,暂未尝试)。

添加上面的库文件和头文件目录,还有lib文件进工程