我正在尝试将原型 defn 从父原型导入到具有以下文件夹结构的子原型中。
|
|--parent.proto
|
|--sub
|--child.proto
父级.proto
message Attribute {
---
}
子原型
import "parent.proto"
message Child {
int32 attributeNo = 1;
com.model.Attribute attribute = 2;
}
目前它给我错误说找不到parent.proto。
请建议。
protoc
在使用指定的目录中查找其导入-I
旗帜。例如,您可以添加-I/home/user/my_awesome_proto_lib
to the protoc
命令行参数,编译器会在那里查找您的导入。
从protoc的帮助页面,关于--proto_path
:
-IPATH, --proto_path=PATH Specify the directory in which to search for
imports. May be specified multiple times;
directories will be searched in order. If not
given, the current working directory is used.
所以目前,当你跑步时protoc
它会寻找parent.proto
in the sub
目录。这显然不是你所需要的。您可以将导入更改为import "../parent.proto"
这将返回到根级别并抓取parent.proto
从那里。但 protobuf 中普遍鼓励的风格是不使用相对导入。
相反,您可以考虑将原型项目的根添加为-I
/--proto_path
flag.
另一种选择是从项目的根目录编译原型文件。你可以cd
到项目的根目录并protoc
从那里。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)