Question

While trying to compile a proto file named UserOptions.proto which has an import named Account.proto using the below command

protoc --proto_path=/home/project_new1/account --java_out=/home/project_new1/source   /home/project_new1/settings/Useroptions.proto

I get the following error :

/home/project_new1/settings/UserOpti‌​ons.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file.

PS: UserOptions.proto present in the directory /home/project_new1/settings
imports Account.proto present in the directory /home/project_new1/account

Proto descriptor files:

UserOptions.proto

package settings;

import "Account.proto";

option java_outer_classname = "UserOptionsVOProto";

Account.proto

package account;

option java_outer_classname = "AccountVOProto";

message Object
{
    optional string userId = 1;
    optional string service = 2;   
}
Was it helpful?

Solution

As the error message states, the file you pass on the command line needs to be in one of the --proto_paths. In your case, you have only specified one --proto_path of:

/home/project_new1/

But the file you're passing is:

/home/project_new1/settings/UserOpti‌ons.proto

Notice that the file is not in the account subdirectory; it's in settings instead.

You have two options:

  • (Not recommended) Pass a second --proto_path argument to add .../settings to the path.
  • (Recommended) Use the root of your source tree as the proto path. E.g.:

    protoc --proto_path=/home/project_new1/ --java_out=/home/project_new1 /home/project_new1/settings/UserOpti‌ons.proto
    

In this case, to import Account.proto, you'll need to write:

import "acco‌​unt/Account.proto";

OTHER TIPS

For those of us who want this really spelled out, here is an example where I have installed the protoc beta for gRPC using NuGet Packages Google.Protobuf, Grpc.Core and Grpc.Tools. My solution packages are one level above my Grpc directory (i.e. at BruTrader\packages). My .proto files are at BruTrader\Grpc\protos.

1. My .proto file:
syntax = "proto3";
import "timestamp.proto";
import "enums.proto";
package BruTrader.Grpc;

message DividendMessage {
    double amount = 1;
    google.protobuf.Timestamp dateUnix = 2;
}

2. my GenerateProto.bat file:
..\packages\Google.Protobuf.3.0.0-beta2\tools\protoc.exe -I..\Grpc\protos -I..\packages\Google.Protobuf.3.0.0-beta2\tools\google\protobuf --csharp_out=..\Grpc\Generated --grpc_out=..\Grpc\Generated --plugin=protoc-gen-grpc=..\packages\Grpc.Tools.0.13.0\tools\grpc_csharp_plugin.exe %1

3. my BuildProtos.bat
call GenerateProto ..\Grpc\protos\masterinstrument.proto
call GenerateProto .\protos\instrument.proto
etc.

4. BuildProtos.bat is executed as a Pre-build event on my Grpc project like this:
CD $(ProjectDir)
CALL "$(ProjectDir)BuildProtos.bat"

For my environment, Windows 10 Pro operating system and C++ programming languaje, I used the protoc-3.12.2-win64.zip that you can downloat it from here. You should open a Windows PowerShell inside the protoc-3.12.2-win64\bin path and then you must execute one of the next commands:

.\protoc.exe -I=C:\Users\UserName\Desktop\SRC --cpp_out=C:\Users\UserName\Desktop\DST C:\Users\UserName\Desktop\SRC\addressbook.proto

Or

.\protoc.exe --proto_path=C:\Users\UserName\Desktop\SRC --cpp_out=C:\Users\UserName\Desktop\DST C:\Users\UserName\Desktop\SRC\addressbook.proto

Note:

1- My source folder is in: C:\Users\UserName\Desktop\SRC

2- My destination folder is in: C:\Users\UserName\Desktop\DST

3- My .proto file is in: C:\Users\UserName\Desktop\SRC\addressbook.proto

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top