c – 使用date_time_formatter时,使用Boost日志库编译错误

前端之家收集整理的这篇文章主要介绍了c – 使用date_time_formatter时,使用Boost日志库编译错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Boost日志库,我想为输出添加时间戳.我从 this example开始,但遇到编译错误.我复制的代码完全如同例子,并将init()函数改为第二个(example_tutorial_formatters_stream_date_time).现在我有以下编译错误
$g++ -Wall -Wextra -O0 -g -isystem /proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include -c main.cpp -o main.o
In file included from /proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include/boost/log/expressions/formatters.hpp:23:0,from /proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include/boost/log/expressions.hpp:26,from main.cpp:109:
/proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include/boost/log/expressions/formatters/date_time.hpp: In instantiation of 'boost::log::v2s_mt_posix::expressions::format_date_time_terminal<T,FallbackPolicyT,CharT>::format_date_time_terminal(const boost::log::v2s_mt_posix::attribute_name&,const fallback_policy&,const string_type&) [with T = boost::posix_time::ptime; FallbackPolicyT = boost::log::v2s_mt_posix::fallback_to_none; CharT = char; boost::log::v2s_mt_posix::expressions::format_date_time_terminal<T,CharT>::fallback_policy = boost::log::v2s_mt_posix::fallback_to_none; boost::log::v2s_mt_posix::expressions::format_date_time_terminal<T,CharT>::string_type = std::basic_string<char>]':
/proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include/boost/log/expressions/formatters/date_time.hpp:229:94:   required from 'boost::log::v2s_mt_posix::expressions::format_date_time_actor<AttributeValueT,boost::log::v2s_mt_posix::fallback_to_none,CharT> boost::log::v2s_mt_posix::expressions::format_date_time(const boost::log::v2s_mt_posix::attribute_name&,const CharT*) [with AttributeValueT = boost::posix_time::ptime; CharT = char]'
main.cpp:156:103:   required from here
/proj/cudbdm/tools/external/boost/inst_1_54_0_cxx11/include/boost/log/expressions/formatters/date_time.hpp:94:68: error: incomplete type 'boost::log::v2s_mt_posix::expressions::format_date_time_terminal<boost::posix_time::ptime,char>::formatter_generator {aka boost::log::v2s_mt_posix::expressions::aux::date_time_formatter_generator_traits<boost::posix_time::ptime,char,void>}' used in nested name specifier
         m_name(name),m_formatter(formatter_generator::parse(format)),m_visitor_invoker(fallback)
                                                                    ^

我尝试使用gcc 4.7.2和4.8.1,带有和不带有-std = c 11标志,但每次都得到相同的结果.似乎错误是在Boost库,这对我来说很奇怪,因为即使官方的例子也没有编译.

解决方法

问题是< boost / log / support / date_time.hpp>需要包括在内.在文件中也在正确的地方说明,但是以某种方式被忽略了.

猜你在找的C&C++相关文章