C/C++ Windwos VS2015 gRPC protobuf 編譯
gRPC是什麼就不介紹了,下面直接進入如何正確編譯gRPC
一、準備和獲取原始碼:
Builds gRPC C and C++ with boringssl.
- 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
)
git clone https://github.com/grpc/grpc
二、獲取gRPC依賴的第三方庫
git submodule update --init
三、編譯依賴第三方庫(這一步應該不需要,只要安裝好依賴的工具直接進入第四步)
需要git,cmake支援
gRPC依賴protobuffer進行訊息編碼,因此需要依賴protobuffer。(詳細見:grpc\third_party\protobuf\cmake\README.md)
cd 到grpc\third_party\protobuf\cmake目錄(我這裡去掉了單元測試)
mkdir build & cd build
mkdir release & cd release
cmake -G "NMake Makefiles" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../..
cd ..
mkdir debug & cd debug
cmake -G "NMake Makefiles" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=../../../../install ../..
cd ..
mkdir solution & cd solution
cmake -G "Visual Studio 14 2015 Win64" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../..
開啟grpc\third_party\protobuf\cmake\build\solution下protobuf.sln編譯生成檔案:protoc.exe libprotobuf.lib libprotoc.lib
四、使用管理員身份執行PowerShell(dos視窗應該也可以)
cd到grpc目錄
執行以下命令
> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules.
> md .build
> cd .build
> cmake .. -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Release
> cmake --build .
開啟grpc\.build\grpc.sln
編譯生成檔案:
protoc.exe libprotobuf.lib libprotoc.libgrpc_cpp_plugin.exe
protoc.exe libprotobuf.lib libprotoc.lib