在Windows 10上的MSVS 2022中无法编译协议缓冲区(Protobuf)示例

发布于 2025-01-19 02:19:51 字数 4148 浏览 1 评论 0原文

我正在尝试从此处编译一个Protobuf示例: https://developers.google.google。 com/protocol-buffers/doc/cpptutorial 。 我的系统配置:

  • Windows 10 Pro,
  • Visual Studion 2022(社区编辑),带有用于桌面开发的C ++软件包,
  • Protobuf v3.20.0(最新版本)。 我已经完成了以下步骤:
  1. 从源代码中编译了Protobuf,成功运行了测试,并使用文件 install 文件夹: bin cmake , include lib
  2. 使用 protoc.exe 生成.cpp和.h文件后,我将它们添加到VS项目中,还包括 libprotobuf.lib 。 VC ++目录 - >包括目录。
  3. 在vs 2022中构建控制台应用程序时,我遇到了很多错误,这在这篇文章中不可能适合,这是其中一些错误:
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  619 
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  633 
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  635 
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   12  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   16  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   22  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   33  
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  263 
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  512 
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  671 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  37  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  59  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  63  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  358 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  607 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  1053    

NB:我只是C ++的初学者,所以我对汇编一无所知过程,如何在vs 2022中进行设置,以及在帖子中包含哪些错误。

I'm trying to compile a protobuf example from here: https://developers.google.com/protocol-buffers/docs/cpptutorial.
My system configuration:

  • Windows 10 Pro,
  • Visual studion 2022 (Community Ed.) with C++ Package for Desktop Development,
  • Protobuf v3.20.0 (Latest Version).
    I've done the following steps:
  1. Compiled protobuf from the source code, successfully ran tests, and got the install folder with the files: bin, cmake, include, lib
  2. After generating .cpp and .h files using protoc.exe, I added them to the VS project and also included libprotobuf.lib.Then, I specified path to the include folder in the project properties -> VC++ Directories -> Include Directories.
  3. While building console application in VS 2022, I was getting a lot of errors, which impossible to fit in in this post, here is some of them:
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  619 
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  633 
Error (active)  E2614   nonvirtual function cannot be declared with 'final' modifier    ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  635 
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   12  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   16  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   22  
Error (active)  E0393   pointer to incomplete class type "tutorial::Person" is not allowed  ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp   33  
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  263 
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  512 
Error (active)  E0470   the global scope has no tag named "TableStruct_addressbook_2eproto" ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  671 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  37  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  59  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  63  
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  358 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  607 
Error (active)  E0077   this declaration has no storage class or type specifier ConsoleApplication1 C:\Cpp_Projects\Protobuf\Demo\Project\ConsoleApplication1\ConsoleApplication1\addressbook.pb.h  1053    

NB: I'm only a beginner in C++, so I understand very little about the compilation process, how to setup it in VS 2022, and what errors are relevant to include in the post.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文