gRPC C++ on Windows
After struggling with this for some time myself, I found that vcpkg does a very good job building gRPC C++ for Windows. Note the requirements are Window 7 or later and VS2015 Update 3 or later. Note that you can configure it the way you want it by using a triplet, e.g. .\vcpkg.exe install grpc --triplet x86-windows-static
After struggling with various errors for many days, I found ready-to-install version here https://github.com/plasticbox/grpc-windows which seems to work satisfactory for my purpose. I post it here in case anyone is in similar situation.
Update: June 2020
According to the project page on GitHub the project is no longer maintained and therefore the example might not work any longer:
May 2019 NOTE: Project is no longer under active development, Idefinitely recommend using vcpkg
In order to install gRPC using vcpkg, launch a console in Windows and execute the following command,
vcpkg install grpc:x64-windows
vcpkg install protobuf protobuf:x64-windows
vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows
vcpkg integrate install
Now we have everything we need, so let's try to generate the message and service interfaces from a proto file using the protoc compiler
If protoc is not available from your console, you might have to add it to your system env PATH. And it will be present in your <vcpkg_install_path>\packages\protobuf_x64-windows\tools\protobuf
folder
Now copy the file to our project/proto folder and run the following commands from there
protoc -I=. --cpp_out=. <yourprotofile>.proto
protoc -I=. --grpc_out=. --plugin=protoc-gen-grpc="<vcpkg_install_path>\packages\grpc_x64-windows\tools\grpc\grpc_cpp_plugin.exe" <your_protofile>.proto
Now let's add content to our CMakeLists.txt file. Take the following code and copy it to our CMakeLists.txt file.
// start //cmake_minimum_required( VERSION 3.1 )project( grpc_example )find_package(gRPC CONFIG REQUIRED)find_package( Protobuf REQUIRED )include_directories(<vcpkg_install_path>/buildtrees/protobuf/src/23fa7edd52-3ba2225d30.clean/src)add_executable( server src/server.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)add_executable( client src/client.cpp proto/helloworld.grpc.pb.cc proto/helloworld.pb.cc)target_link_libraries( server PRIVATE gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )target_link_libraries( client PRIVATE gRPC::grpc++ gRPC::grpc++_reflection gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc_cronet protobuf::libprotoc protobuf::libprotobuf protobuf::libprotobuf-lite )// end //
Now go to our project/build folder and issue the following command to generate a project using CMake. I'll be generating a Visual Studio 2015 solution here, but the choice is up to you.
cmake -G "Visual Studio 14 2015 Win64" ../ -DCMAKE_TOOLCHAIN_FILE=<vcpkg_install_path>/scripts/buildsystems/vcpkg.cmake
cmake build .
cmake --build . --config Release
Now go to the Release folder, and run the server.exe and client.exe