我正在尝试在 Visual C++ 项目中使用 gRPC。
到目前为止我有:
1) 构建gRPC
with vcpkg
: vcpkg install grpc:x64-windows
2) 综合vcpgk
带有视觉工作室的库:vcpkg integrate install
到目前为止,一切都很好——智能感知自动完成命名空间等。
我的客户cpp
文件看起来像这样:
#include "pch.h"
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp\grpcpp.h>
#include "GRPCServerInterface.grpc.pb.h"
#include "FileFormat.pb.h"
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
using namespace GRPCServerInterface;
int main()
{
std::cout << "Hello World!\n";
// prepare send message & payload
IsFormatSupportedInput msg;
msg.set_fileextension(".asp");
// prepare reply
IsFormatSupportedOutput rpl;
// connect
FileHandler::Stub ClientStub = FileHandler::Stub(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
ClientContext context;
// execute rpc
Status status = ClientStub.IsFormatSupported(&context, msg, &rpl);
// handle result
if (status.ok())
{
std::cout << "Format supported says:" << std::endl << "\t formats read: " << rpl.readsupportedformats() << std::endl << "\t formats write: " << rpl.writesupportedformats() << std::endl;
}
else
{
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
}
}
所有消息&proto
文件退出并正常工作,因为我已经在 python 和 c# 项目中使用它们。
构建时,Visual Studio 会生成大量 125 个错误,所有这些错误都在我从未接触过的文件中。
In GRPCServerInterface.pb.h
, 有identifier GOOGLE_DCHECK is undefined
所有其他错误都是member abc may not be initialized
在 grpc 包含的各种头文件中,例如member "google::protobuf::Any::kIndexInFileMessages" may not be initialized
在文件中any.pb.h
。还有更多在type.pb.h
and descriptor.pbp.h
.
最后但并非最不重要的一点是,我收到提示添加#iclude "pch.h"
到自动生成的 protobuf 类grpcserverinterface.grpc.pb.cc
and grpcserverinterface.pb.cc
- 添加它会改变一点,但基本上所有错误仍然存在undefined symbol
and member may not be initialized
。而且我真的不想每次都修改自动生成的代码。
我缺少什么?或者尝试在 Visual Studio 中使用 grpc 只是徒劳的尝试,我应该转向像 bazel 这样的构建框架吗?