gogo.proto:找不到文件。

huangapple go评论103阅读模式
英文:

gogo.proto: File not found

问题

你可以尝试以下方法来解决路径错误:

  1. 确保 gogo.proto 文件存在于 /home/abc/src/github.com/gogo/protobuf/gogoproto/ 目录中。检查文件名的大小写是否正确,并确保文件扩展名为 .proto

  2. 确保你的 image.proto 文件中的导入语句正确指向 gogo.proto 文件的路径。检查路径是否与实际文件路径匹配,包括目录结构和文件名。

  3. 检查你的 Makefile 文件中的 regenerate 目标是否正确设置了 --proto_path 参数。确保该参数指向正确的目录,包括 gogo.proto 文件所在的路径。

  4. 确保你的环境中已正确安装了 Protocol Buffers 和 gogoprotobuf。如果没有安装,可以按照官方文档提供的指南进行安装。

如果你仍然遇到问题,请提供更多详细信息,例如完整的目录结构和文件路径,以便我能够更好地帮助你解决问题。

英文:

protoc --gogofaster_out=. image.proto

I get this error message

>/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto: File not found.
>
>image.proto: Import "/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto" was not found or had errors.

The file is definitely there. I can reach it from the reported path in the error.

My proto file looks like this:

package image;

import "/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto";

message Frame {
required bool fragment = 1; 
required int32  fragmentID = 2; 
required bool lastFragment = 3; 
required bytes data = 4;
}

I have a Makefile in the dir where the proto file is. Looks like this:

regenerate:
--proto_path=../../github.com/gogo/protobuf/gogoproto:../../github.com/gogo/protobuf/protobuf/google/protobuf:. --gogofaster_out=. *.proto

What can I do to resolve the path error?

答案1

得分: 1

根据这个问题,你可以尝试只导入相对路径:

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

确保首先将GOPATH设置为/home/abc

我提到了protobuf PR 241,其中makefile定义了要使用的路径:

regenerate: 
  protoc-min-version --version="3.0.0" 
    --proto_path=$(GOPATH)/src/image:
                 $(GOPATH)/src/github.com/go‌​go/protobuf/protobuf‌​:
                 $(GOPATH)/src/githu‌​b.com/gogo/protobuf/‌​protobuf/google/prot‌​obuf:
                 . --gogo_out=. *.proto 

OP提到了这个线程,指出:

依赖项调用其他依赖项在"google/protobuf/"中,因此这些依赖项也需要正确设置路径。错误信息非常误导人。

当使用gogoproto扩展时,应该使用gogofast_outgofast_out仅适用于不使用任何扩展但需要额外速度的情况。gogofast_out / gofast_out没有副作用。gogofaster_out使大多数字段的nullable=false

英文:

As in this issue, you could try and import only the relative path:

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

Make sure that GOPATH is set to /home/abc first.

I mention protobuf PR 241, where the makefile defines the PATH to use:

regenerate: 
  protoc-min-version --version="3.0.0" 
    --proto_path=$(GOPATH)/src/image:
                 $(GOPATH)/src/github.com/go‌​go/protobuf/protobuf‌​:
                 $(GOPATH)/src/githu‌​b.com/gogo/protobuf/‌​protobuf/google/prot‌​obuf:
                 . --gogo_out=. *.proto 

The OP mention this thread, which points out:

> The dependencies call other dependencies in "google/protobuf/", so these need to be in the path correctly also.
The errors are pretty misleading

> Also when using gogoproto extensions you should use gogofast_out.
gofast_out is only for when you are not using any extensions, but want some extra speed.
gogofast_out / gofast_out has no side effects.
gogofaster_out makes most fields nullable=false.

答案2

得分: 1

  1. 运行go get -u github.com/gogo/protobuf命令来下载依赖到本地目录$GOPATH/pkg/mod
  2. 运行go mod vendor命令来打包你的模块依赖。执行该命令后,你的项目中应该会有一个名为"vendor"的目录,并且在Makefile中应该引用该目录。

Makefile中的命令应该是:

regenerate: 
    protoc-min-version --version="3.0.0" \
    --proto_path=$(GOPATH)/src/image \
    -I vendor/github.com/go‌go/protobuf/protobuf‌​ \
    -I vendor/githu‌​b.com/gogo/protobuf/‌​protobuf/google/prot‌​obuf \
    -I. --gogo_out=. *.proto 

这里,--proto_path-I是相同的。
如果绝对路径包含变量,则模式应为:

-I=${path_variable}/a/sample \
-I=${path_variable}/b/sample \

希望这对某人有所帮助!

英文:
  1. Run <code>go get -u github.com/gogo/protobuf</code> to download the dependencies to local directory <code>$GOPATH/pkg/mod</code>
  2. Run <code>go mod vendor</code> to packaging your module dependencies. After execute this cmd, there should be a directory "vendor" in your project and shall be referred in the Makefile.

The Makefile command should be:

regenerate: 
    protoc-min-version --version=&quot;3.0.0&quot; \
    --proto_path=$(GOPATH)/src/image \
    -I vendor/github.com/go‌​go/protobuf/protobuf‌​ \
    -I vendor/githu‌​b.com/gogo/protobuf/‌​protobuf/google/prot‌​obuf \
    -I. --gogo_out=. *.proto 

Here, --pro_path and -I are the same.<br>
In case the absolute path contains variable then the pattern should be:<br>

-I=${path_variable}/a/sample \
-I=${path_variable}/b/sample \

Hope this might help someone!

答案3

得分: 0

你需要使用--proto_path参数指定gogo.proto目录以搜索导入的文件。

protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
path/to/your/target/protofile --proto_path=$GOPATH/src/ --proto_path=.
英文:

You need to specify the gogo.proto directory to search for imports using --proto_path parameter.

protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
path/to/your/target/protofile --proto_path=$GOPATH/src/ --proto_path=.

huangapple
  • 本文由 发表于 2017年3月26日 16:02:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/43026449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定