生成的Protobuf代码使应用程序崩溃 [英] Generated Protobuf code crashes application

查看:562
本文介绍了生成的Protobuf代码使应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google的协议缓冲区为应用程序实现保存文件.

I'm trying to implement save-file for application, by using Protocol Buffers by Google.

准备工作

已创建一个简单的测试.proto文件以测试功能:

A simple test .proto file has been created to test functionality:

message LessonFile {  
  optional string creator = 1;  
}

创建的.pb.cc和.pb.h包含在项目中. lib和include目录在项目的属性中指定.

Created .pb.cc and .pb.h are included into project. Lib and include directory are specified in project's properties.

问题
将新生成的代码包含到项目中会导致应用程序在运行时崩溃.

Problem
Including newly generated code into project results application crash during runtime.

通过调试崩溃状态,它指向此函数:

By debugging crash state, it pointed on this function:

UnknownFieldSet::UnknownFieldSet()
    : fields_(NULL) {} ---------here---------

当框在上方时指向:

LessonFile::LessonFile()
    : ::google::protobuf::Message() { ---------here---------
    SharedCtor();
}

调用堆栈:

google::protobuf::UnknownFieldSet::UnknownFieldSet (this=0x770e3cc3)
LessonFile (this=0xba64b30) protobuf_AddDesc_LessonFile_2eproto ()
StaticDescriptorInitializer_LessonFile_2eproto (this=0x4bc108)
__static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) global constructors keyed to _Z38protobuf_AssignDesc_LessonFile_2eprotov ()
__do_global_ctors ()
__mingw_CRTStartup () WinMainCRTStartup ()

其他信息
环境:Netbeans; Windows7-64; Qt-4.8.1 + mingw,protobuf-2.4.1.
Protobuf编译过程也存在问题:进行检查始终失败,并显示以下消息:

Additional info
Environment: Netbeans; Windows7-64; Qt-4.8.1 + mingw, protobuf-2.4.1.
Also there were problems with Protobuf compilation process: make check is constantly fails with this messages:

在./include/gtest/gtest-param-test.h:159:0中包含的文件中, 来自./include/gtest/gtest.h:59, 来自src/gtest.cc:34:./include/gtest/internal/gtest-param-util-genic.h:在 :: operator的实例化 测试::内部:: ParamGenerator()const [with T = bool; T1 = 布尔T2 = bool]>:../include/gtest/gtest-param-test.h:1186:28:
从这里需要 ./include/gtest/internal/gtest-param-util-generated.h:80:26:错误: 没有在此范围内声明,也没有声明 在实例化点通过依赖于参数的查找找到 [-fpermissive]在./include/gtest/gtest.h:59:0包含的文件中, 来自src/gtest.cc:34:./include/gtest/gtest-param-test.h:288:58:注意:testing :: internal :: ParamGenerator testing :: ValuesIn(const Container&)>已声明 在这里,稍后在翻译部门

In file included from ./include/gtest/gtest-param-test.h:159:0, from ./include/gtest/gtest.h:59, from src/gtest.cc:34: ./include/gtest/internal/gtest-param-util-generated.h: In instantiation of ::operator testing::internal::ParamGenerator() const [with T = bool; T1 = bool; T2 = bool]>: ./include/gtest/gtest-param-test.h:1186:28:
required from here ./include/gtest/internal/gtest-param-util-generated.h:80:26: error: was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive] In file included from ./include/gtest/gtest.h:59:0, from src/gtest.cc:34: ./include/gtest/gtest-param-test.h:288:58: note: testing::internal::ParamGenerator testing::ValuesIn(const Container&)> declared here, later in the translation unit

成功地编译了 protoc.exe ,并创建了 make install 包含目录和lib * .a/lib * .dll.文件.

though libraries and protoc.exe were compiled successfully and make install created include directory and lib*.a/lib*.dll.a files.

推荐答案

已将评论转换为答案,供将来的观看者使用:

Comments converted to an answer, for future viewers:

  1. 下载MingW + MSYS软件包,然后安装它.
  2. 将MingW的安装文件夹中的"msys"文件夹复制到"C:\ msys",删除"C:\ msys"中的"mingw"文件夹.
  3. 将"C:\ msys \ etc \ fstab"编辑为"C:/QtSDK/mingw/mingw"
  4. 将protobuf源复制到"C:\ msys \ home \"
  5. 打开msys shell,将CD转到"/home//protobuf"
  6. http://eschew.wordpress.com/2009/09/20/building-protobuf-with-mingw-gcc-4-4-0/-项目#2
  7. 运行"./configure --disable-shared"
  8. 运行"make"
  9. 手动将生成的库文件复制到qt库目录(以及头文件-维护目录结构)
  1. Download the MingW + MSYS package then install it.
  2. Copy the "msys" folder in MingW's install folder to "C:\msys", delete the "mingw" folder in "C:\msys".
  3. Edit "C:\msys\etc\fstab" to "C:/QtSDK/mingw /mingw"
  4. Copy the protobuf source to "C:\msys\home\"
  5. Open the msys shell, cd to "/home//protobuf"
  6. http://eschew.wordpress.com/2009/09/20/building-protobuf-with-mingw-gcc-4-4-0/ - Item #2
  7. Run "./configure --disable-shared"
  8. Run "make"
  9. Manually copy the generated library files to the qt library directories (header files as well - maintain directory structure)

这篇关于生成的Protobuf代码使应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆