在协议缓冲区中,如何从上级目录导入文件? [英] In Protocol Buffers, how to import a file from the upper level directory?

查看:33
本文介绍了在协议缓冲区中,如何从上级目录导入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在协议缓冲区文件(pcfg_lm.proto)中具有以下代码:

I have the following code in a protocol buffer file(pcfg_lm.proto):

import "../types/language.proto";

package nlp;

message PCFGProto {
  required Language lang = 1;
}

当然,../types/language.proto中存在一个原始文件.但是,当我发出命令时:

And of course there is a proto file exists at ../types/language.proto. However, when I issue the command:

protoc pcfg_lm.proto --cpp_out=/tmp

这是错误消息:

../types/language.proto: File not found.
pcfg_lm.proto: Import "../types/language.proto" was not found or had errors.
pcfg_lm.proto:6:12: "Language" is not defined.

我认为必须有某种方法可以在不使用-I标志的情况下在上级目录中指定文件名.但是我该怎么做?

I think there must be some way to specify the file names in the upper level directories, without using the -I flag. But how do I do that?

推荐答案

您可以使用-proto_path = 指令指定要搜索导入的目录.如果需要,可以多次使用它.

You can use the --proto_path= directive to specify which directories to search for imports. It can be used multiple times if needed.

正确的--proto_path将取决于在导入文件(language.proto)中如何定义包.

The correct --proto_path will depend on how the package is defined in the imported file (language.proto).

  1. 如果导入的文件(language.proto)包含程序包类型;

指定-proto_path = 父目录 ,然后将导入更改为

specify --proto_path=Parent directory and change the import to

导入"types/language.proto";

import "types/language.proto";

如果导入的文件没有包

指定-proto_path = 父目录/类型 ,然后将导入更改为

specify --proto_path=Parent directory/types and change the import to

导入"language.proto";

import "language.proto";

这篇关于在协议缓冲区中,如何从上级目录导入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆