Hi,

I have 2 proto files: imported.proto and importing.proto.

imported.proto:
  package first;
  message first_msg { optional bool fld = 1; }

importing.proto:
  package second;
  import "test/imported.proto" ;
  message second_msg { optional first.first_msg field1 = 1; }

I have place both files into "test" directory and when invoking protoc like 
this:
  protoc --cpp_out=test -I ./test  -I . test/importing.proto 
test/imported.proto

I getting errors:
  imported.proto:3:30: "first_msg.fld" is already defined in file 
"test/imported.proto".
  imported.proto:1:9: "first_msg" is already defined in file 
"test/imported.proto".

Which indicates to me that when protoc processes test/importing.proto it 
actually resolves and loads imported.proto. Is that correct?
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") ?

Strictly speaking, in case of C++ it is not actually needed to have 
individual .cc/.h files for every .proto, as everything could be placed 
into single .h/.cc. I understand that this might not be possible for other 
languages, for example java, which has to respect "java_outer_classname" 
and "java_package". But for language like C++ I do not see why it is 
important to keep separate files.

I am not saying that when c++ code is generated it should always place code 
generated from all included protos into single file, but merely that such 
option might be convenient in some cases.

Reason I am mentioning possibility of embedding all code into single .h/.cc 
is because currently, assuming that there are two separate invocations of 
protoc to generate imported.pb.* and importing.pb.*,  there is a sort of 
dependency - if I generate code like this:
protoc --cpp_out=test -I ./test  test/imported.proto
protoc --cpp_out=test -I -I .      test/importing.proto

then protoc in both case will succeed, but result would not compile because 
of protobuf_AssignDesc_XXXproto names would not match.
In other words, following has to match:
 1. what flags (-I) I use when compiling test/imported.proto
 2. and how test/imported.proto is imported in other files.

Situation is a bit worse in case of java, as for above example, java 
generated code would actually compile, but would give 
a java.lang.ExceptionInInitializerError at run time.

Thanks

-- 
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