windows - 如何修复 ‘--go_out: protoc-gen-go: The system cannot find the file specified.’ 错误

标签 windows go protocol-buffers

我创建了一个 person.proto ,我想将此文件编译为 *.go 。
我安装了包

go get -u github.com/golang/protobuf/protoc-gen-go



执行以下命令后

.\protoc.exe --go_out=. person.proto



我收到以下错误

--go_out: protoc-gen-go: The system cannot find the file specified.



我想使用缓冲协议(protocol),版本 2

我该如何解决这个错误?

我的原型(prototype)文件:

package communication;

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

最佳答案

描述

不幸的是,据说没有一个核心开发人员在 Windows 上开发,因此我解决了这个问题并为 Windows 开发人员添加了这个答案。

但是,possible duplicate link @Flimzy 提到的那个不起作用,我已经完成了下面的所有 6 个步骤,然后令人惊讶的是,问题已经通过第 7 步解决了。此外,我错误地在 VSCode 终端上运行了该命令。

程序

  • 下载 protoc-win32.zip来自“https://developers.google.com/protocol-buffers/docs/downloads”。
  • 解压文件,然后添加 protoc.exe 的位置到您的 PATH 环境变量。另外,没那么必要,可以复制protoc.exeGOPATH .
  • 更改/导航到文件的 CMD/Powershell 路径,然后运行 ​​protoc.exe --version从命令提示符验证该过程。
  • 验证您的 GOPATH环境变量已设置。
  • 运行go get -u github.com/golang/protobuf/protoc-gen-go来自 CMD/Powershell。这应该将二进制文件安装到 %GOPATH%/bin .
  • 添加确切的%GOPATH%/bin到您的 PATH 环境变量。
  • 打开一个新的 CMD/Powershell,导航到您的 .proto文件然后运行 ​​protoc --go_out=. *.proto


  • 引用文献:
  • How to install protoc-gen-go (Go protocol buffer compiler plugin) in windows?
  • protoc-gen-go: protoc fails to compile in Windows
  • 关于windows - 如何修复 ‘--go_out: protoc-gen-go: The system cannot find the file specified.’ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55594238/

    相关文章:

    编译一个简单的C程序以使用Pixie进行渲染(开源renderman)

    c# - 布数字化仪!制作真实布料的 3d 模型

    go - 如何处理延缓语句中的错误

    Golang 动态访问结构属性

    c# - ProtoBuf-Net 错误消息 - "Nested or jagged lists and arrays are not supported"

    node.js - Google Protobuf - 在 Typescript 中从 JSON 反序列化

    windows - 使用 OAuth 从 Windows 应用程序访问 Google App Engine 应用程序

    c++ - 对于 64 位 Windows,是否有 libusb-win32 的替代方案?

    go - 运行go env时,显示的GOPATH与我在环境变量中设置的内容有所不同吗?

    rest - 通过 REST 发送 Protocol Buffer