gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:48:45 27 4
gpt4 key购买 nike

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

导入“timestamp.proto”;

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

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

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 文件添加到 Visual Studio 项目头文件,以及从我的 .proto 文件生成的其他 .h/.cc 文件。

我不知道如何解决这个问题。我已经验证删除时间戳类型允许项目成功构建。我试过旧版本的 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 文件,以便它引用 Timestamp 类型,如下所示:

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

而不是我引用它的方式:

导入“timestamp.proto”;

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com