https://github.com/boostorg/log/blob/master/example/basic_usage/main.cppからプログラムをコピーしました。main.cpp の名前を mylog.cpp に変更しました。最初に -std=c++0x でコンパイルしました (詳細は以下に示します)。正常にビルドされましたが、実行可能ファイルを実行するとセグメンテーション違反が発生しました。-std=c++0x がなければ、プログラムは正常に動作します。助けてください。私は c++ を初めて使用するので、デバッグ情報を見逃す可能性があります。この問題をデバッグするために必要な情報があれば教えてください。ありがとう
注:このmain.cppの最初の3行のコメントを外しました
#define BOOST_LOG_USE_CHAR
#define BOOST_ALL_DYN_LINK 1
#define BOOST_LOG_DYN_LINK 1
Eclipse から設定をビルドします (このプログラムをビルドするには、Boost ログ ライブラリが必要だと思います):
make all
Building file: ../mylog.cpp
Invoking: GCC C++ Compiler
g++ -I/home/help/usr/local/boost_1_54_0 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"mylog.d" -MT"mylog.d" -o "mylog.o" "../mylog.cpp"
Finished building: ../mylog.cpp
Building target: test
Invoking: GCC C++ Linker
g++ -L/home/help/usr/local/lib -o "test" ./mylog.o -lpthread -lboost_thread -lboost_system -lboost_log_setup -lboost_log
Finished building target: test
ビルド後、このプログラムを実行すると、セグメンテーション違反が発生しました。
$ ./mylog
Segmentation fault (core dumped)
gdb を使用します。それは私を図書館に向ける
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7100c0a in boost::log::v2_mt_posix::attribute_value_set::find(boost::log::v2_mt_posix::attribute_name) const () from /home/fcai/usr/local/lib/libboost_log.so.1.54.0
(gdb) list
73 return strm;
74 }
75
76 int main(int argc, char* argv[])
77 {
78 // This is a simple tutorial/example of Boost.Log usage
79
80 // The first thing we have to do to get using the library is
81 // to set up the logging sinks - i.e. where the logs will be written to.
82 logging::add_console_log(std::clog, keywords::format = "%TimeStamp%: %Message%");
(gdb) bt
#0 0x00007ffff7100c0a in boost::log::v2_mt_posix::attribute_value_set::find(boost::log::v2_mt_posix::attribute_name) const () from /home/fcai/usr/local/lib/libboost_log.so.1.54.0
#1 0x000000000042713f in boost::log::v2_mt_posix::value_extractor<boost::mpl::vector2<std::string, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::log::v2_mt_posix::fallback_to_none, boost::log::v2_mt_posix::expressions::tag::message>::operator() (this=0x7fffffffc6b0, name=..., attrs=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/attributes/value_extraction.hpp:232
#2 0x00007ffff74c379d in boost::log::v2_mt_posix::aux::light_function<void (boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >&)>::impl<boost::log::v2_mt_posix::(anonymous namespace)::chained_formatter<char, boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left, boost::proto::argsns_::list2<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<2> >, 0l> >, boost::log::v2_mt_posix::expressions::attribute_actor<boost::mpl::vector2<std::string, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, boost::log::v2_mt_posix::fallback_to_none, boost::log::v2_mt_posix::expressions::tag::message, boost::phoenix::actor> >, 2l> > > >::invoke_impl(boost::log::v2_mt_posix::aux::light_function<void (boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >&)>::impl_base*, boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >&) () from /home/fcai/usr/local/lib/libboost_log_setup.so.1.54.0
#3 0x0000000000431b64 in boost::log::v2_mt_posix::aux::light_function<void (boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >&)>::operator()(boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >&) const (this=0x652ab8,
args#0=..., args#1=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/detail/light_function.hpp:444
#4 0x00000000004306db in boost::log::v2_mt_posix::basic_formatter<char>::operator() (this=0x652ab8, rec=..., strm=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/expressions/formatter.hpp:157
#5 0x0000000000430806 in boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2_mt_posix::aux::fake_mutex, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char> > (this=0x6507c0, rec=..., backend_mutex=..., backend=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/sinks/basic_sink_frontend.hpp:440
#6 0x000000000042f505 in boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::try_feed_record<boost::mutex, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char> > (this=0x6507c0,
rec=..., backend_mutex=..., backend=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/sinks/basic_sink_frontend.hpp:489
#7 0x000000000042d28e in boost::log::v2_mt_posix::sinks::synchronous_sink<boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char> >::try_consume (this=0x6507c0, rec=...)
at /home/fcai/usr/local/boost_1_54_0/boost/log/sinks/sync_frontend.hpp:145
#8 0x00007ffff7106053 in boost::log::v2_mt_posix::core::push_record_move(boost::log::v2_mt_posix::record&) () from /home/fcai/usr/local/lib/libboost_log.so.1.54.0
#9 0x000000000041f8f1 in push_record (rec=..., this=0x651050) at /home/fcai/usr/local/boost_1_54_0/boost/log/core/core.hpp:308
#10 boost::log::v2_mt_posix::sources::basic_logger<char, boost::log::v2_mt_posix::sources::logger, boost::log::v2_mt_posix::sources::single_thread_model>::push_record_unlocked(boost::log::v2_mt_posix::record&&) (this=0x7fffffffccc0, rec=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/sources/basic_logger.hpp:268
#11 0x000000000041d2e6 in boost::log::v2_mt_posix::sources::basic_composite_logger<char, boost::log::v2_mt_posix::sources::logger, boost::log::v2_mt_posix::sources::single_thread_model, boost::log::v2_mt_posix::sources::features<> >::push_record(boost::log::v2_mt_posix::record&&) (this=0x7fffffffccc0, rec=...) at /home/fcai/usr/local/boost_1_54_0/boost/log/sources/basic_logger.hpp:582
#12 0x000000000041a9b4 in boost::log::v2_mt_posix::aux::record_pump<boost::log::v2_mt_posix::sources::logger>::~record_pump (this=0x7fffffffd170, __in_chrg=<optimized out>)
at /home/fcai/usr/local/boost_1_54_0/boost/log/sources/record_ostream.hpp:279
#13 0x0000000000414de3 in main (argc=1, argv=0x7fffffffd7b8) at ../mylog.cpp:116
(gdb)