c++ - Windows 上使用 C++ 的 google protobuf 时间戳未声明的标识符

标签 c++ protocol-buffers grpc

我有一个 Windows native C++ 项目,它使用 google protobufs(版本 3 语法)和 gRPC。我有一个 .proto 文件,其中包含如下时间戳类型:

导入“timestamp.proto”;

我可以成功生成(使用 protoc.exe).proto 文件中的消息和服务的 .cc 和 .h 文件,没有任何错误或警告。我还可以从 .proto 文件生成 gRPC 的输出,而不会出现错误或警告。

当我在 Visual Studio 项目中使用这些生成的文件时,我在从 .proto 文件生成的 .cc 文件中看到这些错误。它们都与时间戳类型相关:

Error C2491 'scc_info_Timestamp_google_2fprotobuf_2ftimestamp_2eproto': definition of dllimport data not allowed
Error C2491 'TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets': definition of dllimport static data member not allowed
Error C2653 'PROTOBUF_INTERNAL_EXPORT_timestamp_2eproto': is not a class or namespace name
Error C2059 syntax error: '<'
Error C2065 'scc_info_Timestamp_timestamp_2eproto': undeclared identifier
Error C2065 'scc_info_Timestamp_timestamp_2eproto': undeclared identifier
Error C2039 'descriptor_table_timestamp_2eproto': is not a member of ''global namespace''
Error C2065 'descriptor_table_timestamp_2eproto': undeclared identifier

我已将 Timestamp.pb.h/.cc 文件以及从 .proto 文件生成的其他 .h/.cc 文件添加到 Visual Studio 项目头文件中。

我不知道如何解决这个问题。我已经验证删除时间戳类型可以使项目成功构建。我尝试过旧版本的 protobufs。当然,还用谷歌搜索了几个小时......

我的环境:

Windows 10
Visual Studio 2017
vcpkg (Microsoft C++ package manager) used to build Protocol buffers 3.11.3 and gRPC 1.27.1

有什么建议吗?

最佳答案

我已找到此问题的解决方案。这主要是由我的包含文件夹路径引起的。我将 VS 包含路径设置为“\include\google\protobuf”,其中包含从 .proto 文件生成的所有 .h 文件。我需要的是将包含文件夹设置为“\include”。这允许我更改我的 .proto 文件,使其引用时间戳类型,如下所示:

导入“google/protobuf/timestamp.proto”;

而不是我引用它的方式:

导入“timestamp.proto”;

此外 - 我发现我不需要在我的项目中包含“timestamp.pb.cc”。我还没有完全调查为什么会这样 - 但一些测试似乎表明它确实不需要。

关于c++ - Windows 上使用 C++ 的 google protobuf 时间戳未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60233204/

相关文章:

java - 排除Java项目中的特定警告

rest - gRPC 服务器如何调用 REST 端点

c++ - 在 Win32 上,我可以在一段时间内禁用窗口绘制吗?

c++ - 使用 QtCreator 在 C++ 中调试动态加载的库

生成的 Protobuf 上的 Java 反射但找不到类

java - 我们应该使用什么 gRPC 监控和 grpc-java 指标?

go - 使用 golang 客户端的 GRPC Web 请求?

c++ - 如何以编程方式为添加到 FILE 端口的打印机提供目标文件路径?

c++ - 添加析构函数后,在程序调用它之前出现错误

java - 获取 Protocol Buffer 中的字段描述符