2013-07-08 87 views
10

我想使用Boost日誌庫,並且我想向輸出添加時間戳。我從this example開始,但是遇到了編譯錯誤。我完全按照示例複製了代碼,並將init()函數更改爲第二個函數(example_tutorial_formatters_stream_date_time)。現在,我有以下的編譯錯誤:使用date_time_formatter時使用Boost日誌庫編譯錯誤

$ 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) 
                    ^

我用gcc 4.7.2和4.8.1有和沒有-std=c++11標誌試過,但我每次都得到了相同的結果。看來這個錯誤出現在Boost庫中,這對我來說很奇怪,因爲即使官方示例沒有編譯。

+2

嘗試添加'#include '。 –

回答

18

問題是需要包含<boost/log/support/date_time.hpp>。它也在適當的地方在文檔中說明,但不知怎的,在這個例子中被忽略了。