Google智能助理SDK"无法投射"在api / auth.pb.cc中编译错误

时间:2017-12-26 15:32:58

标签: c++11 makefile google-authentication google-assistant-sdk

我尝试编译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自动执行,在此命令中出现以下错误:

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 个答案:

答案 0 :(得分:-1)

我将所有内容设置为全新的,现在它可以正常工作。我想也许有些包括错误。 (但我不知道,为什么现在有效)

  1. 结帐https://github.com/googleapis/googleapis
  2. cd进入googleapis并使用git submodule update --init
  3. 结帐子模块
  4. 运行make LANGUAGE=cpp
  5. 编译子目录*.pb.ccgoogleapis/gens/google/api以及googleapis/gens/google/type
  6. 中的googleapis/gens/google/assistant/embedded/v1alpha2个文件
  7. 将它们放在一起存档
  8. 将该存档与grpcprotobuf库以及一些示例代码链接到可执行文件中。需要安装protobufgrpc,例如第3步:c++ v1alpha1 assistant sdk example
  9. 我将这个脏的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)