0. 基于这篇博客搭建的环境 - https://mp.csdn.net/console/editor/html/106450423
1. 安装grpc
pacman -S mingw-w64-x86_64-grpc
2. grpc测试
编写一个简单的proto文件
person.proto
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
指令
① protoc -I ./ --grpc_out=./ --plugin=protoc-gen-grpc="D:\SoftwareInstall\msys64\mingw64\bin\grpc_cpp_plugin.exe" ./person.proto
② protoc -I ./ --cpp_out=./ ./person.proto
生成
3. Qt 工程环境
DEFINES += _WIN32_WINNT=0x600
BUILD_LIBS_ROOT_PATH = D:\Softwares\ProgramEditor\Path\msys64
BUILD_LIBS_ROOT_64_PATH = $$BUILD_LIBS_ROOT_PATH\mingw64\lib
BUILD_LIBS_ROOT_32_PATH = $$BUILD_LIBS_ROOT_PATH\mingw32\lib
INCLUDEPATH += $$PWD/protoc/ #person.grpc.pb.h 和 person.pb.h所在目录
win32 {
## 标准windows库
contains(QT_ARCH, i386) {
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc_cronet.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc_plugin_support.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc_unsecure.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibprotobuf.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibprotobuf-lite.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibprotoc.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc++.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc++_error_details.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc++_reflection.dll
LIBS += -L$$BUILD_LIBS_ROOT_32_PATH -llibgrpc++_unsecure.dll
} else {
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc_cronet.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc_plugin_support.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc_unsecure.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibprotobuf.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibprotobuf-lite.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibprotoc.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc++.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc++_error_details.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc++_reflection.dll
LIBS += -L$$BUILD_LIBS_ROOT_64_PATH -llibgrpc++_unsecure.dll
}
} else { }
搭建好的环境
和彩云 - http://caiyun.feixin.10086.cn/dl/0r5CsgDMhKoCP 提取密码:YqvC