首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Assistant SDK在api/auth.pb.cc中出现"cannot cast“编译错误

Google Assistant SDK在api/auth.pb.cc中出现"cannot cast“编译错误
EN

Stack Overflow用户
提问于 2017-12-26 23:32:58
回答 1查看 144关注 0票数 0

我尝试编译grpc Google Assistant SDK的新v1alpha2。

为此,我在Google Assistant git存储库中运行make (使用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自动执行的,在这个命令中,我得到了以下错误:

代码语言:javascript
复制
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

感谢您的帮助,祝您节日愉快。

EN

回答 1

Stack Overflow用户

发布于 2017-12-28 03:39:29

我设置的一切都是全新的,现在它可以工作了。我认为可能有些包含路径是错误的。(但我真的不知道,为什么它现在有效)

使用git submodule update --init

  • run make LANGUAGE=cpp

  • compile将https://github.com/googleapis/googleapis

  • cd签出到googleapis和签出子模块在子目录googleapis/gens/google/apigoogleapis/gens/google/type中分配*.pb.cc文件,并将它们一起放入归档

中所示,需要安装protobufgrpc

我把这个脏的makefile放在一起。不是很好,但很管用。

代码语言:javascript
复制
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)
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47980639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档