Protobuf timestamp not found
Solution 1
I had this issue - I had installed thr protoc compiler using the apt package manager (ubuntu) and it put the protoc compiler in somewhere like /usr/local/bin
it seems by default protoc expects and required imports to be present in an include path relative to this .e.g. /usr/local/bin/include/*
next to /usr/local/bin/protoc
.
To fix I removed the installed version with apt and downloaded the latest release from the github page - github.com/protocolbuffers/protobuf/releases look for the protoc download for your os/arch (e.g protoc-3.13.0-linux-x86_64.zip
) this download has the required include (in the inlcude
folder). Just place the include folder next to the binary in your PATH.
Solution 2
My problem was quite simple...
I didn't have the timestamp.proto downloaded locally and as a result it couldn't find it.
I cloned:
https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf
And then when I run my compiler I have to give it the location to locate the timestamp.proto files.
For me it was...
protoc -I profile/ -I MY_CLONED_REPO_LOCATION/protobuf/src profile/profile.proto --go_out=plugins=grpc:profile
Once it knew where it had the path to the source then it could find it with no issues.
Solution 3
I had same problem with protoc 3.0.0 installed from ubuntu repo. I have found another solution, without reinstalling protobuf as @SwiftD suggested, using --proto_path protoc option. In your .proto import should look like (i.e. without path):
syntax = "proto3";
import "timestamp.proto"
Then in the protoc invocation you pass absolute path to your package directory containing timestamp.proto (I use github.com/golang/protobuf/ptypes/timestamp) using --proto_path option.
protoc kcproto.proto --go_out=./ --proto_path=/home/my_home_dir_name/go/src/github.com/golang/protobuf/ptypes/timestamp --proto_path=./
replace /home/my_home_dir_name/ with your go package directory
Solution 4
For mac, I run this in the terminal
PROTOC_ZIP=protoc-3.14.0-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
Note that you can change the version protoc-3.14.0
to whatever your need, for example protoc-3.x.x
Docs: http://google.github.io/proto-lens/installing-protoc.html
mornindew
Updated on June 17, 2022Comments
-
mornindew almost 2 years
Relatively new to GRPC and getting an error in my proto file that I cannot seem to make sense of. I would like to send a time in a message using the "google.protobuf.Timestamp". I cannot seem to import it. What am I doing wrong?
syntax = "proto3"; import "google/protobuf/timestamp.proto"; service ProfileService { rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse); } message ConstructProfileStructFromUserRequest { string transactionID = 1; string User = 2; } message ConstructProfileStructFromUserResponse { string UID = 1; string ContactEmail = 2; google.protobuf.Timestamp DateOfBirth = 3; }
Both in my IDE and my compiler (using the below command) then I get the error
google/protobuf/timestamp.proto: File not found. profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors. profile.proto:21:5: "google.protobuf.Timestamp" is not defined.
Command to run:
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile
Protoc --version
libprotoc 3.0.0
-
Dapo Michaels about 4 yearsWhat exactly did you do @SwiftD after downloading it
-
SwiftD about 4 years@dapo first you need to uninstall any existing protoc then once downloaded you want the binary from the download to be somewhere in your path e.g
/usr/local/bin/protoc
(assuming/usr/local/bin
is in your PATH var) then you just need to place the includes folder from the download in the same folder next to it e.g/usr/local/bin/includes
. should work now from any location, call version flag to confirm -
LeoRado over 3 yearsI installed the protoc compiler to /usr/local/bin, but didn't copy the required imports. This issue got solved after I copied the additional imports to "/usr/local/bin/include'.