Developing a Windows C++ RPC Service -

2,218 views
Skip to first unread message

John Coffey

unread,
Mar 1, 2016, 12:49:01 PM3/1/16
to grpc.io
Hello gRPC group, 

I just spent the last couple of days setting up grpc - not an easy task on Windows.  Anyway, I would like to share some of my experiences here in the hopes that it may help others save some pain and also if I have completely misunderstood the process to elicit feedback to get a better build environment working.

Anyways here are the steps I went through to get grpc and protoc setup for x64 on a Windows 10 machine using Visual Studio 2015
  • install latest CMake and save it in c:\tools\CMake - for this exercise - I used cmake version 3.5.0-rc3
  • change to a folder where I keep external library development - cd c:\main\extlibs
  • open my git for windows MinGW64 shell (effectively a command window) and....
  • git clone https://github.com/grpc/grpc.git grpc
  • cd grpc
  • git submodule update --init
  • export $PATH=/c/tools/CMake/bin:$PATH
  • Open C:\main\extlibs\grpc\vsprojects\grpc.sln in "Visual Studio 2015"
  • Select Debug/x64 from build toolbar and build grpc++unsecure subproject - note that this implies 'Multi-threaded Debug (/MTd)'
  • fix the following error reported when building the protobuf project
    coded_stream.h(1138): error C2220: warning treated as error - no 'object' file generated
    coded_stream.h(1138): warning C4244: 'initializing': conversion from '__int64' to 'int', possible loss of data
    by changing line 1138 from 'int size = end - target;' to 'int size = static_cast<int>(end - target);'
  • Select grpc++unsecure subproject
  • rebuild
  • build grpc++
  • edit the settings for the z library and disable warning 4996 - that warns about using ISO _read/_write apis instead of the old read/write.  This is disabled in the C/C++ All Options/DisableSpecificWarnings) section - do this for all platforms
  • build z.lib
  • At this point, all except for boringssl should compile - boringssl requires a whole bunch more openssl dependencies and it looks like it is an oversight by google, anyways I don't need SSL so its not a problem
  • Next, moving on to google's protobuf build process
    the above repository comes with v3.0.0-beta2 (per) the following
    in my MINGW64 git shell prompt /c/main/extlibs/grpc/third_party/protobuf ((v3.0.0-beta-2))
    However note that this does not include google gmock for the unit tests, we need to disable this by adding a special command line argument to cmake to force it to skip the unit testing
  • Open VS2015 x64 Native Command Prompt and add CMake to the path per path c:\tools\CMake\bin;%PATH% - note that I needed to do this instead of using the MINGW32 prompt for some reason, but I don't recall what that is now
  • Generate the build files from the native command prompt from the cmake/build/release directory using 
  • cmake\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../../
    This will create a set of Makefiles with an install folder in the 'third_party' folder
  • repeat above for a debug build
  • build and install the libraries
    cd release
    nmake
    nmake install
    The last step will create the libraries / headers in third_party/install
  • Add release support for zlib compressed streams:
    Still using the VS2015 x64 Native Command Prompt:
    cd third_party/zlib
    mkdir build && cd build && mkdir release
    cd release
    cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../install ../..
This should eventually spit out a bunch of text and end with
...
[ 89%] Linking C static library zlibstatic.lib
[ 89%] Built target zlibstatic
Scanning dependencies of target example
[ 91%] Building C object CMakeFiles/example.dir/test/example.obj
example.c
[ 94%] Linking C executable example.exe
[ 94%] Built target example
Scanning dependencies of target minigzip
[ 97%] Building C object CMakeFiles/minigzip.dir/test/minigzip.obj
minigzip.c
[100%] Linking C executable minigzip.exe
[100%] Built target minigzip
  • zlib\build\release>nmake install
    Microsoft (R) Program Maintenance Utility Version 14.00.23506.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    [ 45%] Built target zlib
    [ 89%] Built target zlibstatic
    [ 94%] Built target example
    [100%] Built target minigzip
    Install the project...
    -- Install configuration: "Release"
    -- Installing: C:/main/extlibs/grpc/third_party/install/lib/zlib.lib
    -- Installing: C:/main/extlibs/grpc/third_party/install/bin/zlib.dll
    -- Installing: C:/main/extlibs/grpc/third_party/install/lib/zlibstatic.lib
    -- Installing: C:/main/extlibs/grpc/third_party/install/include/zconf.h
    -- Installing: C:/main/extlibs/grpc/third_party/install/include/zlib.h
    -- Installing: C:/main/extlibs/grpc/third_party/install/share/man/man3/zlib.3
    -- Installing: C:/main/extlibs/grpc/third_party/install/share/pkgconfig/zlib.pc
  • if using visual studio build files required to the following (optional) 
    first make a vs2015 folder in the cmake/build
    cmake/build/vs2015 ((v3.0.0-beta-2)) cmake -G "Visual Studio 14 2015 Win64" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../..
    This will create the solution file
  • Next add support for plugins
    Open vsprojects/grpc_protoc_plugins.sln in Visual Studio 2015
    Change the build to release x64
    adjust the library location for each of the subprojects Additional Library Directories should be set to $(SolutionDir)\..\third_party\protobuf\cmake\build\$(Configuration);%(AdditionalLibraryDirectories) - for all platforms
This should set up the libraries and binaries for making the generated code so now on to making clients and servers
  • Add extlibs/grpc/include & extlibs/grpc/third_party/install/include paths to the project include paths for both the clients and servers
  • Add extlibs/grpc/vsprojects/$(PlatformShortName)/$(Configuration) &  extlibs/grpc/third_party/install/lib & extlibs/grpc/third_party/protobuf/$(Configuration) to the additional library directories settings
  • Add gpr.lib;grpc.lib;grpc++_unsecure.lib;libprotobufd.lib;zlib.lib;WSock32.Lib;Ws2_32.lib - for some reason I did not need to add the latter 2 winsock ones to the server (just the client - probably something I did incorrectly in the Visual Studio Project settings for the client)
  • Add a test protoc file (in my case a modified version of the hello world example) called CAService.protoc and generate the message and grpc stubs (NOTE THAT A FULLY QUALIFIED PATH TO THE C++ PLUGIN IS REQUIRED)
  • using the MINGW64 shell prompt (the native Visual Studio one works also) change to the folder containing th eprotoc files and generate the stubs
  • fileprotoc -I . --grpc_out=../src/ --plugin=protoc-gen-grpc=/c/main/extlibs/grpc/vsprojects/x64/Release/grpc_cpp_plugin.exe CAService.proto
  • protoc -I . --cpp_out=../src/ca CAService.proto
  • add the generated cc files to the visual studio project and change the warning level to W2 as the generated code is full of warnings - thanks google!
  • build the server
  • copy the generated code from the server to the client and repeat
I have a problem with this latter step, it seem to me that it would make more sense to make the protoc and generated stubs a static library that could be used by the client and server.  Once the interface has been tied down betwene the client and server in my case, I do not see this changing much.

Anyways I would welcome any feedback to get this process a simpler on my windows environment

Hope this helps others

John Coffey

GoldenBull Chen

unread,
Mar 2, 2016, 2:47:08 AM3/2/16
to John Coffey, grpc.io
some notes to simplify the process:
1. Using "msbuild" instead of opening .sln file with visual studio.
2. "msbuild" has a "/t" option to specify the project to be built in a solution, so boringssl can be skipped without modifying the .sln file.
3. Visual Studio has a feature called "property manager" in which you can load the .prop files in git into your own projects. The .prop file contains the necessary information about including directories, lib directories, lib dependencies, etc.
4. Run "cmake -G "Visual Studio 14 2015" -Dprotobuf_BUILD_TESTS=OFF ." in the protobuf/cmake folder will generate a protobuf.sln file including both Debug and Release configuration. (Actually, MinSizeRel and RelWithDebInfo in addition)

hope these information will help.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/36275171-633f-4e7d-8e1d-f188a2e2b14b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages