使用dep時,我在包含google/protobuf/timestamp.proto眾所周知的類型時遇到問題。我收到錯誤:google/protobuf/timestamp.proto: File not found服務.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 def 的包: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.protogoogle/protobuf/timestamp.proto: File not found.包含時間戳的 .proto 定義的目錄存在:file vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.protovendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto: ASCII text我在本地安裝協議是因為我不想將協議版本鎖定/綁定到該項目:# fetch the protoc compilerOS_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.zipendififeq ($(OS_NAME),Linux)? ? PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zipendifbuild/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我究竟做錯了什么?
1 回答

慕仙森
TA貢獻1827條經驗 獲得超8個贊
protoc
您收到的錯誤與您的路徑有關INCLUDE
。
當您安裝protoc
編譯器時(例如,安裝到/usr/local/bin/protoc
),為了讓它拾取 google 的標準原型定義,例如timestamp.proto
- 這些需要添加到您的INCLUDE
路徑中的某個位置(在 MacOS/Linux 上可能會使用/usr/local/include
)。注意:協議頭文件應該包含在協議編譯器中。
因此,您的原型導入文件通常位于此處:
/usr/local/include/google/protobuf/timestamp.proto
protoc
當編譯器看到如下導入時將引用此路徑:
import "google/protobuf/timestamp.proto";
因此,請檢查您的INCLUDE
路徑并確保protoc
標頭安裝正確。
- 1 回答
- 0 關注
- 147 瀏覽
添加回答
舉報
0/150
提交
取消