我有一个程序,其中有2个.proto文件:
// A.proto, main file
syntax = "proto3";
import "B.proto"
service Greeter {
rpc SayHello (Hello) returns (Hello) {}
}
message Hello {
string name = 1;
someMessage subproto = 2;
}
和第二个.proto文件:
// B.proto, file with message
syntax = "proto3";
import "google/protobuf/timestamp.proto";
message someMessage {
string name = 1;
Timestamp tsmp = 2
}
我使用QMake构建程序。
这是main.pro
INCLUDEPATH += usr/local/include
LIBS += -lgrpc++ -lgrpc -lprotobuf
QMAKE_CXXFLAGS += -L/usr/local/lib pkg-config --libs grpc++ grpc \
pkg-config --cflags protobuf \
pkg-config --libs protobuf \
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
-lprotobuf -lpthread\
-std=c++14\
-I/usr/local/include -pthread\
-Wall -g
PROTOS = prot/A.proto prot/B.proto
# only A.proto in GRPC because there are no services in B.proto
GRPC = prot/A.proto
include(prot/prot.pri)
这是prot.pri
protobuf_decl.name = protobuf headers
protobuf_decl.input = PROTOS
protobuf_decl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h
protobuf_decl.commands = protoc --cpp_out=${QMAKE_FILE_IN_PATH} --proto_path=${QMAKE_FILE_IN_PATH} ${QMAKE_FILE_NAME}
protobuf_decl.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += protobuf_decl
protobuf_impl.name = protobuf sources
protobuf_impl.input = PROTOS
protobuf_impl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.cc
protobuf_impl.depends = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h
protobuf_impl.commands = $$escape_expand(\n)
protobuf_impl.variable_out = SOURCES
QMAKE_EXTRA_COMPILERS += protobuf_impl
grpc_decl.name = protobuf headers
grpc_decl.input = GRPC
grpc_decl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.grpc.pb.h
grpc_decl.commands = protoc --grpc_out=${QMAKE_FILE_IN_PATH} --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin --proto_path=${QMAKE_FILE_IN_PATH} ${QMAKE_FILE_NAME}
grpc_decl.variable_out = HEADERS
QMAKE_EXTRA_COMPILERS += grpc_decl
grpc_impl.name = protobuf sources
grpc_impl.input = GRPC
grpc_impl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.grpc.pb.cc
grpc_impl.depends = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.grpc.pb.h
grpc_impl.commands = $$escape_expand(\n)
grpc_impl.variable_out = SOURCES
QMAKE_EXTRA_COMPILERS += grpc_impl
但是当我尝试构建程序时,编译器给我带来了这样的输出和很多错误:
google/protobuf/timestamp.proto: File not found.
navigation.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
...
但是我的timestamp.proto
文件夹中实际上有/usr/local/include/google/protobuf
。所以我不明白,为什么qmake看不到该文件。请向我解释一下,如何更改代码,以便qmake可以看到现有的timestamp.proto
?