Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using import in .proto file

I tried importing a proto file named test1.proto to another proto file named test2.proto using the import statement

import "com/test/test1.proto"; 

But i get the following error

com/test/test1.proto: File not found. test2.proto: Import "com/test/test1.proto" was not found or had errors. 

I tried in many ways to find the cause of the import error but couldn't. So could someone please tell me the correct way of doing proto file imports in case there is something wrong with the above statement??

like image 740
Aarish Ramesh Avatar asked Jan 15 '14 09:01

Aarish Ramesh


People also ask

How do I import Proto from another project?

In the service project, you need to add a proto file, then add the Protobuf element to the ItemGroup. Then you need to build the project. After that, in the client's project, you need to add the Protobuf element to the ItemGroup and build the project.

How do I change the default value in proto?

proto file with [default = value] after the tag number. If the default value is not specified for an optional element, a type-specific default value is used instead: for strings, the default value is the empty string. For booleans, the default value is false . For numeric types, the default value is zero.

How do I add comments to a proto file?

Adding Comments To add comments to your .proto files, use C/C++-style // and /* ... */ syntax.

What is protoc command?

protoc is a compiler for protocol buffers definitions files. It can can generate C++, Java and Python source code for the classes defined in PROTO_FILE.


1 Answers

You have to use the --proto_path command-line flag (aka -I) to tell protoc where to look for .proto files. If you don't provide a path, by default it will only search the current directory. See the documentation (under "Generating Your Classes" at the end of the page), or type protoc --help.

like image 127
Kenton Varda Avatar answered Oct 07 '22 06:10

Kenton Varda