gpt4 book ai didi

c++ - 生成的 Protobuf 代码使应用程序崩溃

转载 作者:太空狗 更新时间:2023-10-29 23:18:44 32 4
gpt4 key购买 nike

我正在尝试通过使用 Google 的 Protocol Buffers 为应用程序实现保存文件。

准备

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

message LessonFile {  
optional string creator = 1;
}

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

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

通过调试崩溃状态,指向了这个函数:

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

while frame above points on:

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 不断失败并显示以下消息:

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。一个文件。

最佳答案

评论转换为答案,供 future 的观众使用:

  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. 运行“制作”
  9. 手动将生成的库文件复制到qt库目录(头文件也一样——保持目录结构)

关于c++ - 生成的 Protobuf 代码使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13000290/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com