Generated Protobuf code crashes application

2019-07-07 00:49发布

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

Preparation

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

message LessonFile {  
  optional string creator = 1;  
}

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---------

while frame above points on:

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

Call stack:

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 ()

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:

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

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

1条回答
混吃等死
2楼-- · 2019-07-07 01:24

Comments converted to an answer, for future viewers:

  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)
查看更多
登录 后发表回答