It's confusing and I'm unsure whether it's effectively explained in the docs.
Proto file imports are absolute to the proto package and the package structure must be preserved in the filing system structure.
However, the absolute disk location is only important when using protoc
per @Brits comment so that the compiler can find the protos.
So.... Your import for ....\def\protos\ProtoB.proto
should reflect the specific package and service or method or message name that you're importing not its disk location (which is what you're using).
Then, when you protoc
, you should --proto_path
and give (I think absolute not relative) paths to the filing system locations that contain the protos needed to be imported.
Have a look at Any
by way of example.
In a proto, you import "google.protobuf.Any"
, it's package plus the message name.
When you protoc
it, Any
is often already in the include path but, if it weren't, you'd need to --proto_path=/path/to/foo
if foo
is the root directory containing google/protobuf/any.proto
; the proto file must be in a directory called protobuf
in a directory called google
for the import to work.
If you're familiar with Golang and GOPATH
, this mirrors how Go packages are named by their directory (not file) name and referenced locally by their location being in the GOPATH
; it's now different with Go Modules.