You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 03:25:14