[Protocol Buffer] Child Directory에서 Parent Directory 프로토 파일 Import
글 작성자: cjwoov
반응형
|
|--parent.proto
|
|--sub
|--child.proto
위와 같이 디렉터리 구조가 구성되어있고 child.proto에서 자신의 상위 폴더에 위치한 parent.proto를 import 하고 싶을 때가 있다.
문제 되는 경우
parent.proto
syntax = "proto3";
package parent;
message Attribute {
---
}
child.proto
syntax = "proto3";
package child;
import "../parent.proto";
message Child {
parent.Attribute attribute = 1;
}
(현재 명령어를 입력하는 위치가 parent.proto가 있는 폴더라 가정 할 때)
protoc -I=.\ .\parent.proto --cpp_out=".\"
protoc -I=.\sub .\sub\child.proto --cpp_out=".\"
상식적으로 import를 할 때 상대 경로를 써주듯이 "../parent.proto"를 써주면 될 것 같지만 프로토콜 버퍼에서는 지원하지 않는 문법이다.
그렇기에, child.proto에서 parent.proto가 어디에 위치해있는지 모른다.
해결 방법
parent.proto
syntax = "proto3";
package parent;
message Attribute {
---
}
child.proto
syntax = "proto3";
package child;
import "parent.proto";
message Child {
parent.Attribute attribute = 1;
}
(현재 명령어를 입력하는 위치가 parent.proto가 있는 폴더라 가정 할 때)
protoc -I=.\ .\parent.proto --cpp_out=".\"
protoc -I=.\sub -I=.\ .\sub\child.proto --cpp_out=".\"
해결 방법은 간단하다. child.proto에서 import는 경로에 상관없이 파일 이름만 써주고 프로토 파일을 제너레이트 하는 명령어에서 -I 옵션을 여러 번 주면 된다. 단, 순서에 주의할 필요가 있다.
-I=자신의 폴더(child.proto) | -I=import시킬 파일이 있는 폴더(parent.proto) |
반응형
'ETC > Protocol Buffer' 카테고리의 다른 글
[Protocol Buffer] 프로토콜 버퍼 설치하기 (Windows) (3) | 2019.06.23 |
---|---|
[ProtocolBuffer] 프로토콜 버퍼 bytes 필드를 json 변환 시 주의 할 점 (0) | 2019.06.20 |
댓글
이 글 공유하기
다른 글
-
[Protocol Buffer] 프로토콜 버퍼 설치하기 (Windows)
[Protocol Buffer] 프로토콜 버퍼 설치하기 (Windows)
2019.06.23 -
[ProtocolBuffer] 프로토콜 버퍼 bytes 필드를 json 변환 시 주의 할 점
[ProtocolBuffer] 프로토콜 버퍼 bytes 필드를 json 변환 시 주의 할 점
2019.06.20