英文:
gogo.proto: File not found
问题
你可以尝试以下方法来解决路径错误:
- 
确保
gogo.proto文件存在于/home/abc/src/github.com/gogo/protobuf/gogoproto/目录中。检查文件名的大小写是否正确,并确保文件扩展名为.proto。 - 
确保你的
image.proto文件中的导入语句正确指向gogo.proto文件的路径。检查路径是否与实际文件路径匹配,包括目录结构和文件名。 - 
检查你的
Makefile文件中的regenerate目标是否正确设置了--proto_path参数。确保该参数指向正确的目录,包括gogo.proto文件所在的路径。 - 
确保你的环境中已正确安装了 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/gogo/protobuf/protobuf:
                 $(GOPATH)/src/github.com/gogo/protobuf/protobuf/google/protobuf:
                 . --gogo_out=. *.proto 
OP提到了这个线程,指出:
依赖项调用其他依赖项在"
google/protobuf/"中,因此这些依赖项也需要正确设置路径。错误信息非常误导人。
当使用gogoproto扩展时,应该使用
gogofast_out。gofast_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/gogo/protobuf/protobuf:
                 $(GOPATH)/src/github.com/gogo/protobuf/protobuf/google/protobuf:
                 . --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
- 运行
go get -u github.com/gogo/protobuf命令来下载依赖到本地目录$GOPATH/pkg/mod。 - 运行
go mod vendor命令来打包你的模块依赖。执行该命令后,你的项目中应该会有一个名为"vendor"的目录,并且在Makefile中应该引用该目录。 
Makefile中的命令应该是:
regenerate: 
    protoc-min-version --version="3.0.0" \
    --proto_path=$(GOPATH)/src/image \
    -I vendor/github.com/gogo/protobuf/protobuf \
    -I vendor/github.com/gogo/protobuf/protobuf/google/protobuf \
    -I. --gogo_out=. *.proto 
这里,--proto_path和-I是相同的。
如果绝对路径包含变量,则模式应为:
-I=${path_variable}/a/sample \
-I=${path_variable}/b/sample \
希望这对某人有所帮助!
英文:
- Run <code>go get -u github.com/gogo/protobuf</code> to download the dependencies to local directory <code>$GOPATH/pkg/mod</code>
 - 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="3.0.0" \
    --proto_path=$(GOPATH)/src/image \
    -I vendor/github.com/gogo/protobuf/protobuf \
    -I vendor/github.com/gogo/protobuf/protobuf/google/protobuf \
    -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=.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论