3

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.

mpromonet
  • 11,326
  • 43
  • 62
  • 91
  • I had the -exact- same problem. In my case it was because I compiled libprotobuf with a different version of mingw than QT was compiled with. I compiled libprotobuf with the mingw that came packaged with QT Creator... and the problem went away. Not sure if this applies to you as you are not using QT Creator... – Daniel Placek Oct 22 '12 at 22:07
  • I've recompiled Protobuf, using Madde shell (it was included with Qt). Also used additional config parameter:./configure --prefix=/c/QtSDK/mingw/ though, results are the same - execution is faild and Protobuf can't manage *make check*. Also, it seems that error code on app exit (0xc0000005) is defined as "memory access violation". Maybe someone knows somrthing about this type of error. – Дмитрий Званчук Oct 24 '12 at 12:36
  • I'm trying to trace configuration process and it seems that ./configure is working with C:/mingw instead of C:/QtSDK/mingw. Libraries for both are different: 4.7.x and 4.4.0 accordingly. Any advice on how to force it to work with QtSDK? – Дмитрий Званчук Oct 24 '12 at 14:28
  • What I did was: 1. Download the MingW + MSYS package then install it. 2. Copy the "msys" 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\username" 5. Open the msys shell, cd to "/home/username/protobuf" 6. Run "./configure --disable-shared" 7. "make" 8. Manually copy the generated library files to the qt library directories (header files as well) – Daniel Placek Oct 24 '12 at 23:22
  • FYI - MADDE didn't work for me either. I noticed browsing its directories though that it seems to have its own version of mingw as well as different library files... I believe it's targeted at mobile dev only. The MSYS setup I described above gives you a nice shell around the QtSDK environment. – Daniel Placek Oct 24 '12 at 23:25
  • *make check* process has just passed all the tests! I'll let you know if my application manages to actually use Protocol Buffers. BTW, add item "edit the file libstdc++.la in that directory, replacing libstdc++.dll.a with libstdc++.a in the definition for library_names" prior item '6' (taken from http://eschew.wordpress.com/2009/09/20/building-protobuf-with-mingw-gcc-4-4-0/) – Дмитрий Званчук Oct 25 '12 at 09:16
  • YES! It works. At least included files don't crash application anymore! TYVM! – Дмитрий Званчук Oct 25 '12 at 09:23

1 Answers1

1

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)
Daniel Placek
  • 765
  • 5
  • 16