如何在单个命令中编译多个proto文件? [英] How to compile multiple proto files in single command?
问题描述
我在单个目录中有两个proto文件,我正在寻找一种在单个命令中从这些文件生成类的方法。 Protobuf文档说我们需要使用 - proto_path
参数。
I have two proto files inside single directory and I am looking for a way to generate classes from those files in single command. Protobuf documentation says that we need to use --proto_path
argument for this.
C:\shekhar\proto_trial>dir
Volume in drive C is C
Directory of C:\shekhar\proto_trial
07/25/2014 12:16 PM <DIR> .
07/25/2014 12:16 PM <DIR> ..
07/25/2014 12:16 PM <DIR> java_op
07/25/2014 12:16 PM 230 map.proto
07/23/2014 04:24 PM 161 message.proto
07/25/2014 12:17 PM 1,228 response.proto
3 File(s) 1,619 bytes
3 Dir(s) 50,259,398,656 bytes free
我使用了 - proto_path
参数,如下所示
I used --proto_path
argument as shown below
C:\shekhar\proto_trial>protoc
--proto_path=C:\shekhar\proto_trial
--java_out=C:\shekhar\proto_trial\java_op
*.proto
但我收到以下错误
message.proto: File does not reside within any path specified using --proto_path (or -I).
You must specify a --proto_path which encompasses this file.
Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
请建议一些方法将所有原型文件一次性编译。
Please suggest some way to compile all the proto files together in single shot.
推荐答案
问题是你指定 - proto_path
作为绝对路径,但你的原型文件作为相对路径。你可以删除 - proto_path
参数(无论如何都默认为当前目录),或者你可以这样做:
The problem is that you are specifying --proto_path
as an absolute path but your proto files as relative paths. You can either drop the --proto_path
argument (it defaults to the current directory anyway), or you can do:
protoc --proto_path=C:\shekhar\proto_trial
--java_out=C:\shekhar\proto_trial\java_op
C:\shekhar\proto_trial\*.proto
这篇关于如何在单个命令中编译多个proto文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!