代码:
#include <boost/log/support/date_time.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
int main()
{
boost::log::add_file_log(
boost::log::keywords::auto_flush = true,
boost::log::keywords::file_name = "log%Y-%m-%d_%H-%M-%S.%N.log",
boost::log::keywords::rotation_size = 10 * 1024 * 1024,
/*if delete here, the compiler was successful*/
boost::log::keywords::format = "[%TimeStamp%] (%Severity%) : %Message%",
boost::log::keywords::min_free_space=3 * 1024 * 1024
);
}
我尝试编译此代码,但提示信息:“错误ld返回1退出状态”。
如果删除boost::log::keywords::format = "[%TimeStamp%] (%Severity%) : %Message%",
,则可以成功编译此代码。
答案 0 :(得分:3)
您需要构建并链接Boost日志库才能使此代码生效,请参阅http://www.boost.org/doc/libs/1_62_0/libs/log/doc/html/log/installation/config.html。
答案 1 :(得分:0)
当我添加-lboost_log_setup
并重建项目时,此问题已得到解决。
因此,它应该是链接-lboost_system -lboost_thread -lboost_log -lpthread -lboost_log_setup