goctl生成protoc报错:Import “google/protobuf/timestamp.proto“ was not found or had errors.

文章讲述了在使用goctlrpc编译protobuf文件user.proto时遇到的错误,因为找不到import的google/protobuf/timestamp.proto。解决方法是通过添加-I参数指定查找导入文件的路径。
摘要由CSDN通过智能技术生成

Bug

这是我的user.proto 文件,位于D:\Go\workspace\src\Link_Service\app\user\service\user.proto

syntax = "proto3";

package user;
option go_package="./user";
import public "google/protobuf/timestamp.proto";

...


// goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=.

PS D:\Go\workspace\src\Link_Service\app\user\service>目录下执行goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=. 报错,报错信息如下:

PS D:\Go\workspace\src\Link_Service\app\user\service> goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=.
Error: google/protobuf/timestamp.proto: File not found.
      --remote string     The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
                          The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
      --style string      The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md]
  -v, --verbose           Enable log output
      --zrpc_out string   The zrpc output directory


google/protobuf/timestamp.proto: File not found.
user.proto:5:1: Import "google/protobuf/timestamp.proto" was not found or had errors.
user.proto:115:3: "google.protobuf.Timestamp" is not defined.

原因

user.proto 导入了"google/protobuf/timestamp.proto" 文件,但是执行命令时,user.proto不知道去哪里找timestamp.proto。我们只需要指出去哪里找导入文件即可。

这是我的 timestamp.proto 的路径
在这里插入图片描述

解决

执行goctl命令时加入-I 参数指定去哪里找到导入文件

-I: -I 选项来指定 proto 文件的搜索路径。通常,-I 选项后面会跟着一个目录路径,用于告诉 protoc 命令在哪些目录下搜索 import 语句引入的 proto 文件。
goctl rpc protoc user.proto -I . -I C:\Users\666\AppData\Local\JetBrains\GoLand2022.3\protoeditor --go_out=. --go-grpc_out=. --zrpc_out=.

执行,成功

PS D:\Go\workspace\src\Link_Service\app\user\service> goctl rpc protoc user.proto  -I . -I C:\Users\666\AppData\Local\JetBrains\GoLand2022.3\protoeditor --go_out=. --go-grpc_out=.  --zrpc_out=.
Done.
  • 14
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
***含了许多Google Protocol Buffers的头文件,其中也包括了google/protobuf/empty.proto。引用中提到在使用protoc进行编译时,报错找不到google/protobuf/empty.proto文件。而引用中提到解决这个问题的方法是在protoc的安装目录下创建一个软链接,将移动后的protobuf头文件目录连接到/usr/local/usr/include/google。综合这些信息,可以得出结论,google/protobuf/empty.proto是Google Protocol Buffers中的一个头文件,用于定义一个空的消息类型。如果在使用protoc进行编译时找不到该文件,可以尝试根据引用中提供的方法创建一个软链接以解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [protoc-3.4.0-win32](https://download.csdn.net/download/qq_40830236/10458935)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [记录一次protobuf的坑(google/protobuf/XXXXX.proto: File not found.)](https://blog.csdn.net/allenlake09/article/details/120741799)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值