C++分布式框架研究(二)-grpc编译

使用git工具下载源码,我是使用小乌龟,路径是https://github.com/grpc/grpc.git。下载完成后切换分支,我使用v1.16.1

C++分布式框架研究(二)-grpc编译_第1张图片

然后进入源码目录,执行

git submodule update --init

用来初始化依赖模块,相关执行信息如下:

E:\Projects\grpc>git submodule update --init
Submodule 'third_party/abseil-cpp' (https://github.com/abseil/abseil-cpp) registered for path 'third_party/abseil-cpp'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark) registered for path 'third_party/benchmark'
Submodule 'third_party/bloaty' (https://github.com/google/bloaty.git) registered for path 'third_party/bloaty'
Submodule 'third_party/boringssl' (https://github.com/google/boringssl.git) registered for path 'third_party/boringssl'
Submodule 'third_party/boringssl-with-bazel' (https://github.com/google/boringssl.git) registered for path 'third_party/boringssl-with-bazel'
Submodule 'third_party/cares/cares' (https://github.com/c-ares/c-ares.git) registered for path 'third_party/cares/cares'
Submodule 'third_party/gflags' (https://github.com/gflags/gflags.git) registered for path 'third_party/gflags'
Submodule 'third_party/googletest' (https://github.com/google/googletest.git) registered for path 'third_party/googletest'
Submodule 'third_party/libcxx' (https://github.com/llvm-mirror/libcxx.git) registered for path 'third_party/libcxx'
Submodule 'third_party/libcxxabi' (https://github.com/llvm-mirror/libcxxabi.git) registered for path 'third_party/libcxxabi'
Submodule 'third_party/protobuf' (https://github.com/google/protobuf.git) registered for path 'third_party/protobuf'
Submodule 'third_party/zlib' (https://github.com/madler/zlib) registered for path 'third_party/zlib'
Cloning into 'E:/Projects/grpc/third_party/abseil-cpp'...
Cloning into 'E:/Projects/grpc/third_party/benchmark'...
Cloning into 'E:/Projects/grpc/third_party/bloaty'...
Cloning into 'E:/Projects/grpc/third_party/boringssl'...
Cloning into 'E:/Projects/grpc/third_party/boringssl-with-bazel'...
Cloning into 'E:/Projects/grpc/third_party/cares/cares'...
Cloning into 'E:/Projects/grpc/third_party/gflags'...
Cloning into 'E:/Projects/grpc/third_party/googletest'...
Cloning into 'E:/Projects/grpc/third_party/libcxx'...
Cloning into 'E:/Projects/grpc/third_party/libcxxabi'...
Cloning into 'E:/Projects/grpc/third_party/protobuf'...
Cloning into 'E:/Projects/grpc/third_party/zlib'...
Submodule path 'third_party/abseil-cpp': checked out 'cc4bed2d74f7c8717e31f9579214ab52a9c9c610'
Submodule path 'third_party/benchmark': checked out '5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8'
Submodule path 'third_party/bloaty': checked out '73594cde8c9a52a102c4341c244c833aa61b9c06'
Submodule path 'third_party/boringssl': checked out 'b29b21a81b32ec273f118f589f46d56ad3332420'
Submodule path 'third_party/boringssl-with-bazel': checked out '8149b351bf797bd80e063787886b7618f508e451'
Submodule path 'third_party/cares/cares': checked out '3be1924221e1326df520f8498d704a5c4c8d0cce'
Submodule path 'third_party/gflags': checked out '30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e'
Submodule path 'third_party/googletest': checked out 'ec44c6c1675c25b9827aacd08c02433cccde7780'
Submodule path 'third_party/libcxx': checked out '6599cac0965be8e5a835ab7a5684bbef033d5ad0'
Submodule path 'third_party/libcxxabi': checked out '9245d481eb3e890f708ff2d7dadf2a10c04748ba'
Submodule path 'third_party/protobuf': checked out '48cb18e5c419ddd23d9badcfe4e9df7bde1979b2'
Submodule path 'third_party/zlib': checked out 'cacf7f1d4e3d44d871b605da3b647f07d718623f'

官方windows下有两种编译方式,这里采取使用VS2015编译的方式,其预装环境如下:

Windows

To prepare for cmake + Microsoft Visual C++ compiler build

  • 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 yasm and add it to PATH (choco install yasm) - required by boringssl
  • (Optional) Install Ninja (choco install ninja)

boringssl跟openssl类似,作用是使得通信通道安全,可以自行百度。这里假定不使用boringssl,只需要装VS和cmake,git之前已经装了。cmake可以从官网的下载页面上下载https://cmake.org/download/

也可以直接点击这里下载https://cmake.org/files/v3.13/cmake-3.13.0-win32-x86.msi 

装好后 ,在源码目录,可以执行下面4条命令,使用cmake命令创建VS2015工程并编译

> md .build
> cd .build
> cmake .. -G "Visual Studio 14 2015"
> cmake --build . --config Release

在.build\Release文件夹里会有对应的生成文件,.build\third_party里有相关的第三方插件。重要的是.build\third_party\zlib\Release里的zlib.dll和.build\third_party\protobuf\Release里的protoc.exe。grpc使用protobuffer来序列化数据。

C++分布式框架研究(二)-grpc编译_第2张图片

grpc的头文件在源码目录的include文件夹,整个都是。lib的话,对于c++,依赖.build\Release文件夹里的grpc.lib和grpc++.lib,另外,从proto文件生成C++文件时,需要protoc.exe和grpc_cpp_plugin.exe

至此grpc已编译完成。

 

 

 

你可能感兴趣的:(com_grpc)