C++提升日志记录编译错误 (Linux)

C++ boost logging compile error (linux)

本文关键字:错误 Linux 编译 记录 日志 C++      更新时间:2023-10-16

谁能告诉我我做错了什么?

在控制台上运行此操作会产生以下错误:

# c++ -I/var/local/boost_1_46_1/log.cpp -o log -lboost-log
log.cpp: 在函数中 'void init()â: log.cpp:11:错误:"提升::日志记录"尚未声明 log.cpp:13:错误:尚未声明"提升::FLT" 日志.cpp:13:错误:"日志记录"尚未声明 日志.cpp:13:错误:"日志记录"尚未声明

我也尝试过从 stage 和/usr/local/lib 目录显式链接库。

我的日志.cpp:

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/filters.hpp>
using namespace std;
void init()
{
    boost::logging::core::get()->set_filter
    (
        boost::flt::attr< boost::logging::trivial::severity_level >("Severity") >= boost::logging::trivial::info
    );
}
}
int main(int, char*[]) {
    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
    BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
    BOOST_LOG_TRIVIAL(info) << "An informational severity message";
    BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
    BOOST_LOG_TRIVIAL(error) << "An error severity message";
    BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
}

如果我省略void init()函数,这段代码将编译......

需要以下命名空间重定义才能使用这些教程:

namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace fmt = boost::log::formatters;
namespace flt = boost::log::filters;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;

http://boost-log.sourceforge.net/libs/log/doc/html/log/how_to_read.html

你确定你的#include是正确的吗?试试#include <boost/log/core/core.hpp>