Windows + VS2017 use gRPC

gRPC official Windows installation instructions:

  • 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)

On the Windows source code to compile and install gRPC still very troublesome need MSVC compiler, git, cmake, Perl, go, yasm, Ninja and other tools, some tools you can use to install choco (package management tool on Windows) to install.

Preparing the environment

       https://git-scm.com/ download git on, the current version 2.23.0.

       https://cmake.org/download/ download cmake on download cmake-3.15.3-win64-x64.zip, when unpacked mode position, where the tool cmake bin directory to the system environment variable Path.

  Installation choco

  

  Install Perl, go, yasm etc.

  

  Use choco install activeperl very slow on my computer is very slow, but also directly in the official website to download the user need to register the landing, too much, the last direct download third-party websites, directly to install!

  

  

  

Download Source gRPC

  Create a new folder named grpc_plugs, right-click the blank space choose Git Bash Here

  git clone https://github.com/grpc/grpc.git 

  cd grpc enter grpc folder, a newer version of the current checkout

  git checkout  v1.23.0

  View the current version

  git branch -v 

  Download dependent

  git submodule update  --init

  Performing operations that require network down, please be patient ...

 

  After the download is complete, locate and open the file ./grpc/third_party/zlib/gzguts.h found 

  #ifdef _WIN32

  #inlcude <stddef.h>

  #endif

  Changed

  #ifdef _WIN32

  #include <stddef.h>

  #pragma warning(disable:4996)

  #endif

  To shield some warning, I feel nothing practical effect, but did so only.

 

VS2017 compile the source code gRPC

  mkdir .build

  cd .build

  cmake –version

  cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release

  Configuring makefile, the process is relatively long, there was no error on nothing issue during what will be generated grpc.sln.

  cmake --build .

  VS2017 above compilation operation command, and directly open grpc.sln perform the same effect of compilation.

  Wait patiently compiled ...

  After completion of the compiler generated dependencies gRPC and third-party libraries lib static library file, as shown in FIG below:

   

  

HelloWorld

  gRPC comes C ++ HelloWorld example located. \ grpc \ examples \ cpp \ helloworld

  New air in VS2017 C ++ project gRPCTest

  The helloworld.proto copied to the project directory

  The resulting protoc.exe copied to the project directory

  Run cmd execute the project directory protoc compiler generates a command to generate source code files helloworld.pb.h, helloworld.pb.cpp, helloworld.grpc.pb.h, helloworld.grpc.pb.cpp.

  protoc -I="./protos" --grpc_out="./protos" --plugin=protoc-gen-grpc=“E:\LearningOpensourceLib\gRPC\grpc_plugs\grpc\.build\Debug\grpc_cpp_plugin.exe " "./protos\hw.proto"

  protoc -I="./protos" --cpp_out="./protos" "./protos\hw.proto"

  Copy grpc_cpp_plugin.exe, greeter_client.cc, greeter_server.cc to the project directory

  The documents are to be added to the project, the final project is structured as follows:

   

  Select Debug - x64 build configuration

  

  Configure include directory and lib directory and lib Import: Add me here direct absolute path

  

  

   

  We need to configure the preprocessor definitions _WIN32_WINNT = 0x0A00, otherwise it will be reported "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" error.

  

  The client code to add std :: cin.get () flash window avoid retire:

  

  Server code:

  

  When compiling the server, please shield the main function of client code

  Compile client, please shield the service side of the main function of the code

  Generate renamed exe file and put together zlibd.dll

  

  Each running grpc-server.exe and grpc-client.exe

  

Guess you like

Origin www.cnblogs.com/MakeView660/p/11511136.html