How to import a file from the top-level directory in the buffer protocol?

I have the following code in the protocol buffer file (pcfg_lm.proto):

import "../types/language.proto"; package nlp; message PCFGProto { required Language lang = 1; } 

And, of course, there is a proto file at .. /types/language.proto. However, when I issue the command:

 protoc pcfg_lm.proto --cpp_out=/tmp 

Here is the error message:

 ../types/language.proto: File not found. pcfg_lm.proto: Import "../types/language.proto" was not found or had errors. pcfg_lm.proto:6:12: "Language" is not defined. 

I think there must be some way to specify file names in top-level directories without using the -I flag. But how do I do this?

+8
c ++ protocol-buffers
source share
1 answer

You can use the directive - proto_path = to specify directories for import searches. If necessary, it can be used several times.

The correct path --proto_path will depend on how the package is defined in the imported file (language.proto).

  • If the imported file (language.proto) contains package types,

    specify - proto_path = Parent directory and change the import to

    import "types / language.proto";

  • If the imported file does not have a package

    specify - proto_path = Parent directory / types and change the import to

    import "language.proto";

+16
source share

All Articles