C++11 谷歌助手SDK“;不能施放“;api/auth.pb.cc中的编译错误

C++11 谷歌助手SDK“;不能施放“;api/auth.pb.cc中的编译错误,c++11,makefile,google-authentication,google-assistant-sdk,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文件,我可以链接到我的基本项目中。(嵌入式助手.proto有两个导入语句:导入“google/api/annotations.proto”;导入“google/type/latlng.proto”

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

为此,我在Google Assistant git存储库中运行make(使用cpp语言输出),生成了
*.pb.cc
*.ob.h
文件。然后我尝试将
/google/api
/google/type
*.pb.cc
文件编译成
.o
文件,我可以链接到我的基本项目中。(嵌入式助手.proto有两个导入语句:
导入“google/api/annotations.proto”;导入“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
make生成的命令:
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
输出:
googleapis/gens/google/api/auth.pb.cc:552:23:错误:无法将“::google::protobuf::RepeatedPtrField<::google::api::AuthenticationRule>”强制转换到其私有基类
'google::protobuf::internal::RepeatedPtrFieldBase'
规则\内部交换(&其他->规则);
^
/usr/local/include/google/protobuf/repeated_field.h:776:41:注意:此处声明为私有
类RepeatedPtrField PROTOBUF_FINAL:专用内部::RepeatedPtrFieldBase{
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
googleapis/gens/google/api/auth.pb.cc:553:27:错误:无法将“::google::protobuf::RepeatedPtrField<::google::api::AuthProvider>”强制转换到其私有基类
'google::protobuf::internal::RepeatedPtrFieldBase'
提供者\内部交换(&other->providers\);
^
/usr/local/include/google/protobuf/repeated_field.h:776:41:注意:此处声明为私有
类RepeatedPtrField PROTOBUF_FINAL:专用内部::RepeatedPtrFieldBase{
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
googleapis/gens/google/api/auth.pb.cc:936:30:错误:无法将“::google::protobuf::RepeatedPtrField<::google::api::AuthRequirement>”强制转换到其私有基类
'google::protobuf::internal::RepeatedPtrFieldBase'
需求\内部交换(和其他->需求);
^
/usr/local/include/google/protobuf/repeated_field.h:776:41:注意:此处声明为私有
类RepeatedPtrField PROTOBUF_FINAL:专用内部::RepeatedPtrFieldBase{
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
产生了3个错误。
make:**[googleapis/gens/google/api/auth.pb.o]错误1

谢谢你的帮助,祝你假期愉快

我把所有东西都设置得非常新,现在都可以用了。我想可能有些include paths是错的。(但我不知道,为什么现在可以用)

  • 签出
    https://github.com/googleapis/googleapis
  • 将cd放入
    googleapis
    并使用
    git子模块更新--init签出子模块
  • 运行
    make LANGUAGE=cpp
  • 编译子目录
    googleapis/gens/google/api
    googleapis/gens/google/type
    googleapis/gens/google/assistant/embedded/v1alpha2
  • 把它们放在一起归档
  • 将归档文件与
    grpc
    protobuf
    库以及一些示例代码链接到一个可执行文件中。
    protobuf
    grpc
    需要安装,如步骤3所示:
  • 我把这个脏的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)
    

    我发现了这一点。这是由gRPC和protobufs版本混合造成的。请始终使用您正在构建的gRPC分支引用的相同版本的protobufs。