2

I am trying to use Timestamp and have imported it in protobuf message -

import "google/protobuf/timestamp.proto";

message TriggerDataMsg {
    google.protobuf.Timestamp start_time = 1;
    google.protobuf.Timestamp end_time = 2;
    google.protobuf.Timestamp next_fire_time = 3;
    google.protobuf.Timestamp previous_fire_time = 4;
    sint32 priority = 13;
}

When trying to compile with protoc compiler to generate Java classes, its failing with the below error -

 [echo] compiling proto sources...
 [exec] google/protobuf/timestamp.proto:35:8: Option "csharp_namespace" unknown.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:24:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:25:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:26:5: "google.protobuf.Timestamp" is not defined.
 [exec] com/vmware/nsx/management/backup/model/trigger_data.proto:27:5: "google.protobuf.Timestamp" is not defined.

I am not sure why its checking for "csharp_namespace" even though I am generating Java classes. Any workaround which I can try to get rid of this error ?

Rahul Vedpathak
  • 1,346
  • 3
  • 16
  • 30
  • "I am not sure why its checking for "csharp_namespace"" Because that's in the timestamp.proto file. – Andy Turner Jul 13 '20 at 11:03
  • Yeah but why its looking for that. And I dont want to generate any classes for csharp. So how to get rid of this error ? – Rahul Vedpathak Jul 13 '20 at 11:06
  • I suspect it's red-herring and the issue is really `"google.protobuf.Timestamp" is not defined`. You'll want to reference `google/protobuf/timestamp.proto` in your `--proto_path` when you generate your source. Timestamp is bundled with protoc in `./include/google/protobuf/timestamp.proto`. And then you'll want to import [Timestamps](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/util/Timestamps) in your implementation. – DazWilkin Jul 13 '20 at 17:35
  • @RahulVedpathak it is importing the file you asked it to import, via the import statement. That file contains things that may or may not be relevant to you, but all are processed, because there is no way to know that they are not relevant to you. – Andy Turner Jul 14 '20 at 11:14

1 Answers1

5

If you want protoc to automatically import something, it needs to be in an /include folder next to your protoc binary.

Reference

If I remember correctly, protoc looks for includes relative to the protoc binary. So if protoc is in /usr/local/bin, then it will look in /usr/local/include.

This worked perfectly for me on Windows to solve:

Import "google/protobuf/wrappers.proto" was not found or had errors.
Jeff Maass
  • 3,632
  • 3
  • 26
  • 30
Austin Peña
  • 300
  • 4
  • 11