Google Assistant SDK "cannot cast" api/auth.pb.cc 中的编译错误



我试图编译GRPC Google Assistant SDK的新V1alpha2。

为此,我在Google Assistant Git存储库中运行(使用CPP语言输出),该存储库生成了我的*.pb.cc*.ob.h文件。然后,我尝试将/google/api/google/type *.pb.cc文件编译到.o文件中,这些文件可以链接到我的基本项目中。(embedded_assistant.proto有两个导入语句:import "google/api/annotations.proto"; import "google/type/latlng.proto";)。

我还尝试用/google/protobuf/google/rpc进行编译。

它是由makefile自动化的,在此命令下,我会收到以下错误:

make generated command:
g++ -c -I/usr/local/include -pthread -I./googleapis/gens -I./grpc  -std=c++11 googleapis/gens/google/api/auth.pb.cc -o googleapis/gens/google/api/auth.pb.o
output:
googleapis/gens/google/api/auth.pb.cc:552:23: error: cannot cast '::google::protobuf::RepeatedPtrField< ::google::api::AuthenticationRule>' to its private base class
    'google::protobuf::internal::RepeatedPtrFieldBase'
rules_.InternalSwap(&other->rules_);
                    ^
/usr/local/include/google/protobuf/repeated_field.h:776:41: note: declared private here
class RepeatedPtrField PROTOBUF_FINAL : private internal::RepeatedPtrFieldBase {
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
googleapis/gens/google/api/auth.pb.cc:553:27: error: cannot cast '::google::protobuf::RepeatedPtrField< ::google::api::AuthProvider>' to its private base class
    'google::protobuf::internal::RepeatedPtrFieldBase'
providers_.InternalSwap(&other->providers_);
                        ^
/usr/local/include/google/protobuf/repeated_field.h:776:41: note: declared private here
class RepeatedPtrField PROTOBUF_FINAL : private internal::RepeatedPtrFieldBase {
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
googleapis/gens/google/api/auth.pb.cc:936:30: error: cannot cast '::google::protobuf::RepeatedPtrField< ::google::api::AuthRequirement>' to its private base class
    'google::protobuf::internal::RepeatedPtrFieldBase'
requirements_.InternalSwap(&other->requirements_);
                            ^
/usr/local/include/google/protobuf/repeated_field.h:776:41: note: declared private here
class RepeatedPtrField PROTOBUF_FINAL : private internal::RepeatedPtrFieldBase {
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
make: *** [googleapis/gens/google/api/auth.pb.o] Error 1

感谢您的任何帮助

我设置了所有新事物,现在可以使用。我认为也许有些途径是错误的。(但是我真的不知道,为什么现在起作用)

  1. 结帐https://github.com/googleapis/googleapis
  2. CD进入googleapis,并使用git submodule update --init结帐子模型
  3. 运行make LANGUAGE=cpp
  4. conectilectorys googleapis/gens/google/apigoogleapis/gens/google/typegoogleapis/gens/google/assistant/embedded/v1alpha2
  5. 中的*.pb.cc文件
  6. 将它们放在档案中
  7. 将存档与grpcprotobuf库一起链接到可执行文件中。protobufgrpc需要安装,例如在步骤3中的此处:C V1alpha1助手SDK示例

我把这个肮脏的makefile放在一起。不是真的很好,但是要解决问题。

GOOGLEAPIS_GENS_PATH = ./googleapis/gens
API_CCS = $(shell find ./googleapis/gens/google/api -name '*.pb.cc')
TYPE_CCS = $(shell find ./googleapis/gens/google/type -name '*.pb.cc')
ASSISTANT_CCS = $(shell find ./googleapis/gens/google/assistant/embedded/v1alpha2 -name '*.pb.cc')
CC = g++
FLAGS += -I$(GOOGLEAPIS_GENS_PATH)
FLAGS += -std=c++11
SRC = $(API_CCS) $(TYPE_CCS) $(ASSISTANT_CCS)
OBJ = $(SRC:%.cc=%.o)
PROG_FLAGS = $(FLAGS)
PROG_FLAGS += `pkg-config --libs grpc++ grpc`
PROG_FLAGS += `pkg-config --cflags --libs protobuf`
PROG_FLAGS += -I./googleapis/gens/google/assistant/embedded/v1alpha2
PROG_SRC = main.cpp
PROG_OBJ = $(PROG_SRC:%.cpp=%.o)
all: prog
prog: assistant_api.ar $(PROG_SRC)
    $(CC) $(PROG_FLAGS) $(PROG_SRC) assistant_api.ar -o prog
assistant_api.ar: $(OBJ)
    ar r $@ $?
$(OBJ): $(SRC)
    $(CC) -c $(FLAGS) $*.cc -o $*.o
clean:
    rm -rf *.o assistant_api.ar $(OBJ)

最新更新