gpt4 book ai didi

c++ - boost 日志到文件不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:18:30 33 4
gpt4 key购买 nike

我不明白为什么这个示例代码不能正常工作。我的编译器说被调用的函数不是声明的命名空间的成员。这是 Boost 日志的示例代码,为什么它不起作用?我需要做什么?

我已经定义了 BOOST_LOG_DYN_LINK,并且包含了所有应该包含的 header 。此外,boost 是通过 yum 从 fedora repos 安装的,根据 yum,boost 版本是 1.55.0

示例:http://www.boost.org/doc/libs/1_55_0/libs/log/example/doc/tutorial_file.cpp

错误

main.cpp:33:5: error: ‘add_file_log’ is not a member of ‘logging’
logging::add_file_log(
^
main.cpp:34:10: error: ‘file_name’ is not a member of ‘keywords’
keywords::file_name = "sample_%N.log", /*< file name pattern >*/
^
main.cpp:35:10: error: ‘rotation_size’ is not a member of ‘keywords’
keywords::rotation_size = 10 * 1024 * 1024, /*< rotate files every 10 MiB... >*/
^
main.cpp:36:10: error: ‘time_based_rotation’ is not a member of ‘keywords’
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
^
main.cpp:36:49: error: ‘sinks::file’ has not been declared
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/

代码

#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>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;

void init()
{
logging::add_file_log
(
keywords::file_name = "sample_%N.log",
keywords::rotation_size = 10 * 1024 * 1024,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
keywords::format = "[%TimeStamp%]: %Message%"
);

logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
}

调用

g++ -c -DBOOST_LOG_DYN_LINK -o main.cpp.o main.cpp

链接器标志:-lboost_program_options -lboost_log -lboost_filesystem -lboost_system -lboost_thread -lpthread

详细日志:https://gist.github.com/HSchmale16/d4dd5656a47ce82c63b2

最佳答案

检查您的头文件是否缺少任何内容,并将 -lboost_log_setup 包含到您的编译器/链接器调用中。

关于c++ - boost 日志到文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30008812/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com