简体   繁体   English

使用date_time_formatter时,使用Boost日志库进行编译错误

[英]Compilation error with Boost log library when using date_time_formatter

I'm trying to use the Boost log library, and I want to add a timestamp to the output. 我正在尝试使用Boost日志库,我想在输出中添加时间戳。 I started out from this example , but I ran into compilation error. 我从这个例子开始,但我遇到了编译错误。 I copied the code exactly as in the example, and changed the init() function to the second one (example_tutorial_formatters_stream_date_time). 我完全按照示例复制了代码,并将init()函数更改为第二个(example_tutorial_formatters_stream_date_time)。 Now I have the following compilation error: 现在我有以下编译错误:

$ 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, FallbackPolicyT, CharT>::fallback_policy = boost::log::v2s_mt_posix::fallback_to_none; boost::log::v2s_mt_posix::expressions::format_date_time_terminal<T, FallbackPolicyT, 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, boost::log::v2s_mt_posix::fallback_to_none, 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)
                                                                    ^

I tried using gcc 4.7.2 and 4.8.1 with and without the -std=c++11 flag, but I got the same result every time. 我尝试使用带有和不带-std=c++11标志的gcc 4.7.2和4.8.1,但每次都得到相同的结果。 It seems that the error is in the Boost library, which is strange to me as even the official example doesn't compile. 似乎错误在Boost库中,这对我来说很奇怪,因为即使是官方示例也无法编译。

The problem is that <boost/log/support/date_time.hpp> needs to be included. 问题是需要包含<boost/log/support/date_time.hpp> It is also stated in the documentation at the proper place, but is somehow left out of the example. 它也在适当的地方的文档中说明,但在某种程度上被排除在示例之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM