在使用dep时,我遇到了包含google/protobuf/timestamp.proto熟知类型的问题。
我得到一个错误:google/protobuf/timestamp.proto: File not found
service.proto:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
package com.rynop.platform;
option go_package = "rpc";
service PlatformService {
rpc Test(EmptyMessage) returns (EmptyMessage);
}
message EmptyMessage { }
message A {
string summary = 1;
google.protobuf.Timestamp start = 2;
}
message B {
repeated A foos = 1;
}安装包含时间戳.proto定义的软件包:
dep ensure -add github.com/golang/protobuf/ptypes/timestamp 运行protoc并获取错误:
build/bin/protoc -Ivendor -I. --twirp_typescript_out=version=v6:./clients/ts-json/ rpc/service.proto
google/protobuf/timestamp.proto: File not found.包含时间戳的.proto定义的目录存在:
file vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto
vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto: ASCII text我之所以在本地安装protoc,是因为我不想将protoc版本锁定/绑定到此项目:
# fetch the protoc compiler
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Darwin)
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-osx-x86_64.zip
endif
ifeq ($(OS_NAME),Linux)
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip
endif
build/protoc build/bin/protoc:
mkdir -p build/protoc/bin build/bin
cd build/protoc && curl -L -o protoc.zip $(PROTOC_URL) && \
unzip protoc.zip && mv bin/protoc ../bin/protoc我做错了什么?
发布于 2019-06-12 11:33:29
您收到的protoc错误与您的INCLUDE路径有关。
当你安装protoc编译器(例如/usr/local/bin/protoc)时,为了让它获得谷歌的标准原型定义,比如timestamp.proto --这些需要添加到你的INCLUDE路径下的某个地方(在MacOS/Linux上,你可以使用/usr/local/include)。注意: protoc头文件应该包含在protoc编译器中。
因此,您的proto导入文件通常位于以下位置:
/usr/local/include/google/protobuf/timestamp.proto当protoc编译器看到像这样的导入时,将引用此路径:
import "google/protobuf/timestamp.proto";因此,请检查您的INCLUDE路径,并确保正确安装了protoc标头。
https://stackoverflow.com/questions/56551570
复制相似问题