在哪里设置 protoc 的路径以导入标准 Protocol Buffers

Muk*_*uka 8 protocol-buffers dart grpc protoc

如果需求我设置pathprotoc获得进口标准协议缓冲器(protobuf的),像empty.prototimestamp.proto在Windows和飞镖?

protoc为然:

protoc --dart_out=grpc:lib/src/protos/generated -Iprotos protos/organization.proto --plugin=protoc-gen-dart=D:\Users\Samuel\AppData\Roaming\Pub\Cache\bin\protoc- gen-dart.bat

出现以下错误

google/protobuf/empty.proto:找不到文件。organization.proto:未找到导入“google/protobuf/empty.proto”或有错误。organization.proto:14:27: 未定义“google.protobuf.Empty”。

在插件上的IntelliJ 中Settings,定义了标准原型 (*.proto) 的位置:Protobuf Supportpath

在此处输入图片说明

此外,这path是在 IntelliJ 中定义的Project Structure\ Global Libraries

在此处输入图片说明

organization.proto导入google/protobuf/empty.proto使用Empty类的代码:

syntax = "proto3";

package auge.protobuf;

import "google/protobuf/empty.proto";

service OrganizationService {

    rpc GetOrganizations (google.protobuf.Empty) returns (OrganizationsResponse) {}
}
Run Code Online (Sandbox Code Playgroud)

IntelliJ 分析器识别出IDEA 上的import "google/protobuf/empty.proto"Empty类,但protoc找不到。

环境是:

  • 所以:Windows 7 x64
  • 协议:libprotoc 3.6.1
  • 飞镖:2.2.0-edge

Igo*_*tis 1

假设你有/some/path/to/google/protobuf/empty.proto,你需要传递--proto_path=/some/path/to/以便 protoc 可以找到它。