Visual Studio 2022集成Protobuf报错:PROTOBUF_NAMESPACE_OPEN无存储类/类型说明符
Windows 10 + VS2022配置Protobuf编译报错求助
我正在Windows 10系统的Visual Studio 2022(Visual C环境)中配置Protobuf,但生成的pb.h和pb.cc文件编译时出现大量报错,典型错误如:PROTOBUF_NAMESPACE_OPEN this declaration has no storage class or type specifier。我刚从Go语言转用C,推测是遗漏了C++开发者默认会完成的配置步骤。
复现步骤
- 参考Protobuf相关教程及官方Windows C++安装文档,使用vcpkg安装Protobuf
- 调用vcpkg包目录下的protoc.exe,将以下.proto文件编译为pb.h和pb.cc文件:
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; }
- 创建空C++项目,将生成的pb.h和pb.cc文件添加到项目中,编译时触发报错
内容的提问来源于stack exchange,提问作者Linus Griebsch
相关产品推荐
相关产品推荐

