java - How do I import protobuf files from one folder in another folder in Eclipse? -
i have existing eclipse project including google protocol buffers. i'm trying add new .proto
in new folder , include .proto
in original folder.
when try build get:
..\shared\panicshared.proto: backslashes, consecutive slashes, ".", or ".." not allowed in virtual path
how reference .proto
in different folder in eclipse? if use absolute file path project not portable.
if import "panicshared.proto" without path import line not error inside panicshared.proto have:
enum paniclevel { normal = 0; etc. }
when try use in message though:
import "panicshared.proto"; message panicpremium { repeated paniclevel panicpremiumlevels = 11; }
i error:
[protoc] panicpremium.proto:9:12: "paniclevel" not defined.
[protoc] [libprotobuf warning google/protobuf/descriptor.cc:5411] warning: >unused import: "panicpremium.proto" imports "panicshared.proto" not used.
i have solved problem doing relative includes.
so if structure:
project +- dir1 +- file1.proto +- dir2 +- file2.proto
and want file1.proto
include file2.proto
do:
protoc -i ../dir2 <other args need> file1.proto
and in file1 say:
import "file2.proto";
here worked through example on machine:
$ find `pwd` -type f /tmp/so/shared/panicshared.proto /tmp/so/main/main.proto $ cat /tmp/so/shared/panicshared.proto enum paniclevel { normal = 0; } $ cat /tmp/so/main/main.proto import "panicshared.proto"; message panicpremium { repeated paniclevel panicpremiumlevels = 11; } $ cd /tmp/so/shared $ protoc -i . panicshared.proto --cpp_out=. $ g++ panicshared.pb.cc -c -o panicshared.pb.o $ cd /tmp/so/main $ protoc -i . -i ../shared main.proto --cpp_out=. $ g++ main.pb.cc -c -o main.pb.o -i ../shared $ protoc --version libprotoc 2.5.0 $ cd /tmp/so/ $ find `pwd` -type f /tmp/so/shared/panicshared.pb.cc /tmp/so/shared/panicshared.proto /tmp/so/shared/panicshared.pb.h /tmp/so/shared/panicshared.pb.o /tmp/so/main/main.pb.o /tmp/so/main/main.pb.h /tmp/so/main/main.proto /tmp/so/main/main.pb.cc
Comments
Post a Comment