首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么protobufs proto3 AssignDescriptors抛出std::system_error?

为什么protobufs proto3 AssignDescriptors抛出std::system_error?
EN

Stack Overflow用户
提问于 2022-04-05 21:45:36
回答 1查看 98关注 0票数 0

我用的是Proc3.19.4

消息定义

代码语言:javascript
运行
复制
syntax = "proto3";
package wibble;
option cc_enable_arenas = true;
option optimize_for = CODE_SIZE;

message Test {
  string id = 1;
  string name = 2;
}

客户端代码capi

代码语言:javascript
运行
复制
#include <google/protobuf/util/json_util.h>
#include <test.pb.h>

#include <string>

int main() {
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  wibble::Test msg{};
  msg.set_id("wibble");
  msg.set_name("friznit");

  std::string asJSON{};
  google::protobuf::util::JsonPrintOptions jopts{};
  jopts.add_whitespace = true;
  jopts.preserve_proto_field_names = true;
  google::protobuf::util::MessageToJsonString(msg, &asJSON,
                                              jopts);  // crashes here
  std::cout << asJSON << std::endl;

  google::protobuf::ShutdownProtobufLibrary();
}

堆栈跟踪

代码语言:javascript
运行
复制
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) where
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff7bf9859 in __GI_abort () at abort.c:79
#2  0x00007ffff7e82911 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7e8e38c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff7e8e3f7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7e8e6a9 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7e8573f in std::__throw_system_error(int) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00005555555c2eee in void std::call_once<google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const* (*)(), std::once_flag*, google::protobuf::Metadata const&)::{lambda()#1}>(std::once_flag&, google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const* (*)(), std::once_flag*, google::protobuf::Metadata const&)::{lambda()#1}&&) ()
#8  0x00005555555c2bb9 in google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const* (*)(), std::once_flag*, google::protobuf::Metadata const&) ()
#9  0x000055555556b790 in wibble::Test::GetMetadata (this=0x7fffffffe600) at src/protoc/test.pb.cc:153
#10 0x00005555555c5439 in google::protobuf::Message::GetDescriptor() const ()
#11 0x00005555555f222b in google::protobuf::util::MessageToJsonString(google::protobuf::Message const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, google::protobuf::util::JsonPrintOptions const&) ()
#12 0x000055555556d009 in main () at src/main.cpp:29

传递给wibble::Test::GetMetadata的参数的检查

代码语言:javascript
运行
复制
::PROTOBUF_NAMESPACE_ID::Metadata Test::GetMetadata() const {
  return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
      &descriptor_table_test_2eproto_getter, &descriptor_table_test_2eproto_once,
      file_level_metadata_test_2eproto[0]);
}

(gdb) p descriptor_table_test_2eproto_getter
$2 = {const google::protobuf::internal::DescriptorTable *(void)} 0x55555556b44a <descriptor_table_test_2eproto_getter()>

(gdb) p descriptor_table_test_2eproto_once
$4 = {_M_once = 0}

(gdb) p file_level_metadata_test_2eproto
$5 = {{descriptor = 0x0, reflection = 0x0}} // suspicious?

我怀疑我缺少了它所期望的库(尽管我已经检查了ldd capi列出的所有库)。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2022-04-05 23:38:24

这个问题的答案很有帮助:std::call_once

与-pthread链接解决了问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71758737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档