For example:
a.proto
package Test;
message A{
required string name=1;
}
b.proto
package Test;
import "a.proto";
message B{
required A a=1;
}
for this case ,protoc b.proto will see this :
import Test1 "a.pb"
thanks for reading my poor English
If two files are in the same package, one shouldn't import the other, but rather both filenames should be passed to protoc together.
If they aren't actually meant to be in the same package, this is a dupe of #8.
Actually, regardless of the bug where generated Go code imports a foo.pb path (#8, I see it, it's at least worked around by f7a7cb5a401616f8f2533b684d9a2fdc3d29ec14), there's some confusion in the air here.
You say two proto files in the same package should not import each other, and should just be passed to protoc together, but that doesn't seem to work:
$ cat a.proto
syntax = "proto3";
package helloworld;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
$ cat b.proto
syntax = "proto3";
package helloworld;
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
$ protoc --go_out=plugins=grpc:. a.proto b.proto || echo FAIL
a.proto:6:17: "HelloRequest" is not defined.
a.proto:6:40: "HelloReply" is not defined.
FAIL
$ protoc --go_out=plugins=grpc:. b.proto a.proto || echo FAIL
a.proto:6:17: "helloworld.HelloRequest" seems to be defined in "b.proto", which is not imported by "a.proto". To use it here, please add the necessary import.
a.proto:6:40: "helloworld.HelloReply" seems to be defined in "b.proto", which is not imported by "a.proto". To use it here, please add the necessary import.
FAIL
This fails for me as well. When using a glob pattern I get this error:
"Counter" is not defined.
they are in the same package and in the same folder.
I'm not sure why this is closed, I still can't get two protofiles in the same package to work with what @dsymonds described. If I import it I get this error for every variable:
counter.proto:20:19: "clipboard.Counter.name" is already defined in file "counter.proto".
if I remove the import and use a *.proto I get this error
clipboard.proto:27:12: "Counter" is not defined.
Friendly ping @dsymonds -- I definitely see a conflict between what you said and how protoc actually behaves, and would appreciate a real clarification.
@dsymonds Ping on this one. I met the same issue.
I misspoke. If a.proto refers to a type in b.proto, it should import it.
@dsymonds OK. It works. Thanks.
@dsymonds Thanks man, you saved my day!
Most helpful comment
Actually, regardless of the bug where generated Go code imports a
foo.pbpath (#8, I see it, it's at least worked around by f7a7cb5a401616f8f2533b684d9a2fdc3d29ec14), there's some confusion in the air here.You say two proto files in the same package should not import each other, and should just be passed to protoc together, but that doesn't seem to work: