问题描述
我尝试使用import语句将一个名为test1.proto的原型文件导入另一个名为test2.proto的原型文件中
I tried importing a proto file named test1.proto to another proto file named test2.proto using the import statement
import "com/test/test1.proto";
但是我收到以下错误
com/test/test1.proto: File not found.
test2.proto: Import "com/test/test1.proto" was not found or had errors.
我尝试了很多方法来找到导入错误的原因,但是找不到.因此,如果上述声明有问题,有人可以告诉我进行原型文件导入的正确方法吗?
I tried in many ways to find the cause of the import error but couldn't. So could someone please tell me the correct way of doing proto file imports in case there is something wrong with the above statement??
推荐答案
您必须使用-proto_path
命令行标志(也称为 -I
)来告诉 protoc
在哪里查找 .proto
文件.如果您不提供路径,默认情况下它将仅搜索当前目录.请参阅文档(在页),或输入 proto --help
.
You have to use the --proto_path
command-line flag (aka -I
) to tell protoc
where to look for .proto
files. If you don't provide a path, by default it will only search the current directory. See the documentation (under "Generating Your Classes" at the end of the page), or type protoc --help
.
这篇关于在.proto文件中使用导入时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!