Hi Feng Xiao,

Thanks for prompt reply

You should invoke protoc using the following command:
> protoc --cpp_out=. test/importing.proto test/imported.proto
>
 
I am actually working on a build system and in my case all file names are 
an absolute path, not relative. With absolute path method suggested above 
(without -I) fails with
$ google/protobuf/2.3.0/gcc_4.1.2/64/bin/protoc --cpp_out=/mypath/test 
/mypath/test/importing.proto /mypath/test/imported.proto
/mypath/test/importing.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).

Looks like in general case I do need to set -I to some value. The only 
remaining thing - understand what the correct value for -I.
 

> You passed in both "-I ./test" and "-I .". That confused protoc. For every 
> proto file protoc will use a relative path to identify it and that's also 
> the path used in "import" statements. For the protos passed in command 
> line, it will determine its path name by matching and stripping the prefix 
> found in "-I" arguments. So the unique name for "test/importing.proto" will 
> be "importing.proto" and "test/imported.proto" will be "imported.proto". 
> Then when compiling "importing.proto", protoc try to find the proto file in 
> the "import test/imported.proto" statement. "test/test/imported.proto" will 
> be tried first and then it finds "test/imported.proto". In the eyes of 
> protoc, there are 3 proto files: importing.proto, improted.proto, 
> test/imported.proto. The first two are in the command line and the third is 
> found through import statement. It then leads to the error message you see.
> You can use the command line I suggested above, or you can change the 
> "import test/imported.proto" to "import imported.proto". Both approaches 
> can fix the problem. Their difference lies in the unique names of the proto 
> files. In the former approach, "test/importing.proto" and 
> "test/imported.proto" are their names and generated files will retain the 
> name prefix (i.e., a directory named "test" will be created in the output 
> path and importing.pb.cc|h imported.pb.cc|h will be put into that 
> directory). If using the other approach, generated files will be put 
> directly in the path you specified.
>

Thanks for detailed explanation. I have suspected something along those 
lines after brief glance thru protoc source code.
 

>  
>
>> If that's the case, then theoretically it should not be necessary to 
>> provide both files on command line in order to generate all required code, 
>> as protoc has all required info already.
>>
>> My question - is it possible to tell protoc that it should generate files 
>> for all "resolved" files by specifying in command line only top level one 
>> ("importing.proto") ?
>>
> No.
>
Do you know if such approach was ever considered? If it was considered and 
rejected - I'd appreciate if you can point me place where I can get more 
info on subject.

BTW, I could not locate any documentation that describes protoc command 
line arguments, default plugin's arguments and perhaps guidelines on usage.
Would appreciate if you can help me locate such docs.

Leonid

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to