美文网首页
在windows上构建grpc

在windows上构建grpc

作者: topillar | 来源:发表于2017-10-16 15:48 被阅读685次

    一、使用CMAKE+NMAKE 法

    使用VC BUILD 2015编译grpc_1.6.6

    环境:

    win7_x64,VC BUILD TOOLS2015

    开始:

    (一)、安装工具

    1.安装Visual C++ Build Tools2015.3(典型安装,在path中加入C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt)

    2.安装cmake:3.8.2

    3.安装ActivePerl:ActivePerl-5.26.0.2600

    4.安装golang:go1.9.1 windows/amd64

    5.安装nasm:2.13.01

    验证安装是否安装成功:

    cmake -version

    perl -version

    go version

    nasm -v

    如果出现错误,请检查是否安装成功;若安装成功,则需要检查安装目录是否添加到环境变量path中。

    (二)、下载源码

    1.grpc-1.6.6.zip解压到D:/grpc-1.6.6

    2.benchmark-1.2.0.zip解压到D:/grpc-1.6.6/third_party/benchmark

    3.boringssl-master.zip解压到D:/grpc-1.6.6/third_party/boringssl

    4.c-ares-cares-1_12_0.zip解压到D:/grpc-1.6.6/third_party/cares/cares

    5.gflags-2.2.1.zip解压到D:/grpc-1.6.6/third_party/gflags

    6.protobuf-3.4.1.zip解压到D:grpc-1.6.6/third_party/protobuf

    6.zlib-1.2.11.zip解压到D:/grpc-1.6.6/third_party/zlib

    除grpc外,只要按照上面的路径解压到相应的目录即可。注意一定要将c-ares-cares-1_12_0.zip(grpc1.6.x貌似与c-ares-cares-1_13_0不兼容)解压到D:/grpc-1.6.6/third_party/cares/cares目录,否是编译会报错。

    (三)、编译

    1.编写脚本do_build.bat

    @echo off

    ::Release,Debug,RelWithDebInfo

    set CMAKE_BUILD_TYPE=%1%

    ::x86,x64

    set PLATFORM=%2%

    set OUTPUT_PATH=%3%

    set CMAKE_PATH=%4%

    if not exist %PLATFORM% (

    mkdir %PLATFORM%

    )

    cd %PLATFORM%

    if %PLATFORM% == x86 (

    call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86

    )

    if %PLATFORM% == x64 (

    call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64

    )

    echo cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%

    ::CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%构建类型(Release,Debug,RelWithDebInfo)

    ::EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH%可执行程序的路径

    ::LIBRARY_OUTPUT_PATH=%OUTPUT_PATH%静态库的路径

    ::CMAKE_C_FLAGS_RELEASE="/MT /WX-"使用静态运行时库,禁止将警告视为错误

    ::CMAKE_CXX_FLAGS_RELEASE="/MT /WX-"使用静态运行时库,禁止将警告视为错误

    ::BUILD_SHARED_LIBS=0生成静态库

    cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%

    nmake grpc grpc++ grpc_cpp_plugin protoc

    主要作用是根据传入的参数生成nmake文件,其中"/MT /WX-"是传递给cl编译器的参数,分别为"使用静态运行时库"和"禁止将警告视为错误"。这个有个技巧如果想要将其他的参数传递给编译器,只需要在后面添加即可。

    2.编写脚本build_x64.bat

    @echo off

    set CURRENT_DIR=%~dp0

    set CMAKE_BUILD_TYPE=Release

    set PLATFORM=x64

    set OUTPUT_PATH=%CURRENT_DIR%/x64/bin

    set CMAKE_PATH=%CURRENT_DIR%/../

    call do_build.bat %CMAKE_BUILD_TYPE% %PLATFORM% %OUTPUT_PATH% %CMAKE_PATH%

    @pause

    生成Release x64平台库文件

    3.开始编译

    将build_x64.bat和do_build.bat脚本,拷贝到D:/grpc-1.6.6/cmake目录下

    运行build_x64.bat进行编译

    ===============================================================

    二、使用CMAKE+NINJA

    Windows7

    Vc2017/VC build tools 2015.3

    SDK8.1

    1、fork官方grpc

    2、修改v1.7.x中的.gitmodules:

    [submodule "third_party/boringssl-with-bazel"]

    path = third_party/boringssl-with-bazel

    url =https://boringssl.googlesource.com/boringssl

    ===>

    [submodule "third_party/boringssl-with-bazel"]

    path = third_party/boringssl-with-bazel

    url =https://github.com/google/boringssl.git

    3、git clone --recursive -b v1.7.xhttps://github.com/topillar/grpc.gitgrpc-v1.7.x

    4、编译

    方法1、

    > md .build

    > cd .build

    > call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

    > cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release

    > cmake --build .

    方法2(VC BUILD TOOL 2015.3):

    1. 编写脚本do_build.bat

    @echo off

    ::Release,Debug,RelWithDebInfo

    set CMAKE_BUILD_TYPE=%1%

    ::x86,x64

    set PLATFORM=%2%

    set OUTPUT_PATH=%3%

    set CMAKE_PATH=%4%

    if not exist %PLATFORM% (

    mkdir %PLATFORM%

    )

    cd %PLATFORM%

    if %PLATFORM% == x86 (

    call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86

    )

    if %PLATFORM% == x64 (

    call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64

    )

    echo cmake -G "Ninja" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%

    cmake -G Ninja -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%

    2. 编写脚本build_x64.bat

    @echo off

    set CURRENT_DIR=%~dp0

    set CMAKE_BUILD_TYPE=Release

    set PLATFORM=x64

    set OUTPUT_PATH=%CURRENT_DIR%/x64/bin

    set CMAKE_PATH=%CURRENT_DIR%/../

    call do_build.bat %CMAKE_BUILD_TYPE% %PLATFORM% %OUTPUT_PATH% %CMAKE_PATH%

    @pause

    3、编译:将build_x64.bat和do_build.bat脚本,拷贝到D:/grpc-v1.7.x/cmake目录下,运行build_x64.bat,完毕后运行cmake --build .

    本文主要来自:http://www.cnblogs.com/dongc/p/6876362.html , 感谢!

    相关文章

      网友评论

          本文标题:在windows上构建grpc

          本文链接:https://www.haomeiwen.com/subject/umtfattx.html