我将翻译如下:
我正在尝试使用Google的Protocol Buffers实现应用程序的保存文件功能。
准备工作
已创建一个简单的测试.proto文件以测试功能:
message LessonFile {
optional string creator = 1;
}
已创建.pb.cc和.pb.h并包含在项目中。Lib和include目录在项目属性中指定。
问题
将新生成的代码包含到项目中会导致运行时应用程序崩溃。
通过调试崩溃状态,发现问题出在这个函数上:
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编译过程中的问题:make check 不停地失败并显示以下消息:
在此处实例化时, ./include/gtest/internal/gtest-param-util-generated.h:80:26: 错误: 没有声明此范围内的“testing::internal::ParamGenerator()”,也没有找到依赖于参数的查找声明 [-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&)>。
虽然libraries和protoc.exe已经成功编译,并且make install已经创建了包含目录和lib*.a/lib*.dll.a文件。