1. 程式人生 > 其它 >Windows下C++使用grpc

Windows下C++使用grpc

技術標籤:grpcc++windows

Windows下使用grpc

安裝grpc

參考 https://blog.csdn.net/danxingxian_go/article/details/104176878

git clone https://github.com/grpc/grpc.git
cd grpc
git submodule update --init #會拉取比較多的程式碼
編譯x64
windows在windows shell模式下可以使用cmake,如果不行需要安裝cmake
切至grpc目錄 
mkdir build
cd bulid
cmake .. -G "Visual Studio 16 2019" -A x64

cmake後會建立vs工程,ALL_BUILD執行 然後INSTALL進行安裝,細節可參考連結
當前有有出現一個錯誤,在生成grpc.lib時編譯失敗
錯誤類似“‘string’ : is not a member of ‘std’, header file problem”
修復: 在對應錯誤檔案中加上 #include<string> 可以修復

使用grpc

在使用grpc時需要安裝protoc,對於原始碼安裝grpc時會對應生成protoc.exe檔案
在嘗試編譯helloworld.proto用例時出錯

protoc -I. --grpc_out=./ --plugin=protoc_gen-grpc=grpc_cpp_plugin helloworld.proto
'protoc-gen-grpc' 不是內部或外部命令,也不是可執行的程式或批處理檔案。
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.

解決辦法:protoc-gen-grpc對應plugin需要為絕對路徑

protoc -I. --grpc_out=./ --plugin=protoc-gen-grpc="C:\\Program Files (x86)\\grpc\\bin\\grpc_cpp_plugin.exe" helloworld.proto

其他的可以參考的用例比較多