What protobuf version are you using? Also, are you linking against a
libprotobuf that has the same version as the protoc that was used to
generate your code? It's important for the version to match, because for
C++ we frequently change the interface between the generated code and the
runtime library.

On Sat, Apr 1, 2017 at 2:36 PM, Xuanting Cai <caixuant...@gmail.com> wrote:

> Hi
>
> I am running some very simple code, but I got Segmentation fault.
> I compiled it with bazel and some proto complie library for bazel.
>
> Here is my code in .cc file
>
> string ToString(const Message& message) {
> TextFormat::Printer printer;
>   printer.SetSingleLineMode(true);
>
>   string proto_in_line_string;
>   printer.PrintToString(message, &proto_in_line_string);
>
>   return proto_in_line_string;
> }
>
> Here is my code in test.cc file
>
> struct ProtoHelperFixture {};
>
> BOOST_FIXTURE_TEST_SUITE(ProtoHelperTests, ProtoHelperFixture)
>
> BOOST_AUTO_TEST_CASE(ToStringTest) {
> TimeInterval time_interval;
> TextFormat::ParseFromString(
> R"(begin_time: "2017-01-01 10:00:00")"
> R"(end_time: "2017-01-01 10:30:00")",
> &time_interval);
> LOG(INFO) << ToString(time_interval);
> }
>
> BOOST_AUTO_TEST_SUITE_END()
>
> Run it in gdb, I got
>
> #0  0x0000002965707954 in ?? ()
> #1  0x00007ffff7f2da5d in 
> google::protobuf::Arena::AllocateAligned(std::type_info
> const*, unsigned long) ()
>    from /home/caixuanting/.cache/bazel/_bazel_caixuanting/
> 6f27b1af69abf374829e79d372f6b04b/execroot/myth-trading-
> system/bazel-out/local-opt/bin/utils/../_solib_k8/
> libexternal_Scom_Ugithub_Ugoogle_Uprotobuf_Slibprotobuf_Ulite.so
> #2  0x00007ffff7f2da92 in google::protobuf::Arena::AddListNode(void*,
> void (*)(void*)) ()
>    from /home/caixuanting/.cache/bazel/_bazel_caixuanting/
> 6f27b1af69abf374829e79d372f6b04b/execroot/myth-trading-
> system/bazel-out/local-opt/bin/utils/../_solib_k8/
> libexternal_Scom_Ugithub_Ugoogle_Uprotobuf_Slibprotobuf_Ulite.so
> #3  0x00007ffff7cc23ef in 
> google::protobuf::FileDescriptorProto::New(google::protobuf::Arena*)
> const ()
>    from /home/caixuanting/.cache/bazel/_bazel_caixuanting/
> 6f27b1af69abf374829e79d372f6b04b/execroot/myth-trading-
> system/bazel-out/local-opt/bin/utils/../_solib_k8/
> libexternal_Scom_Ugithub_Ugoogle_Uprotobuf_Slibprotobuf.so
> #4  0x00007ffff7270acb in google::protobuf::MessageLite::ParseFromArray(void
> const*, int) ()
>    from /usr/lib/x86_64-linux-gnu/libprotobuf.so.8
> #5  0x00007ffff72b30f3 in 
> google::protobuf::EncodedDescriptorDatabase::Add(void
> const*, int) ()
>    from /usr/lib/x86_64-linux-gnu/libprotobuf.so.8
> #6  0x00007ffff727a40a in 
> google::protobuf::DescriptorPool::InternalAddGeneratedFile(void
> const*, int) () from /usr/lib/x86_64-linux-gnu/libprotobuf.so.8
> #7  0x00007ffff72ac41c in google::protobuf::protobuf_
> AddDesc_google_2fprotobuf_2fdescriptor_2eproto() () from
> /usr/lib/x86_64-linux-gnu/libprotobuf.so.8
> #8  0x00007ffff7dea10a in call_init (l=<optimized out>, argc=argc@entry=1,
>     argv=argv@entry=0x7fffffffe428, env=env@entry=0x7fffffffe438) at
> dl-init.c:78
> #9  0x00007ffff7dea1f3 in call_init (env=<optimized out>, argv=<optimized
> out>,
>     argc=<optimized out>, l=<optimized out>) at dl-init.c:36
> #10 _dl_init (main_map=0x7ffff7ffe1c8, argc=1, argv=0x7fffffffe428,
> env=0x7fffffffe438)
>     at dl-init.c:126
> #11 0x00007ffff7ddb30a in _dl_start_user () from
> /lib64/ld-linux-x86-64.so.2
> #12 0x0000000000000001 in ?? ()
> #13 0x00007fffffffe660 in ?? ()
> #14 0x0000000000000000 in ?? ()
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to