C ++ boost日志编译错误(linux)

时间:2011-05-19 17:44:43

标签: c++ linux boost

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

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

  

# c ++ -I / var / local / boost_1_46_1 / log.cpp -o log -lboost-log
  log.cpp:在函数中运行init()â:   log.cpp:11:错误:âboost::loggingâ尚未声明   log.cpp:13:错误:âboost::fltâ尚未声明   log.cpp:13:错误:âloggingâ尚未声明   log.cpp:13:错误:âloggingâ尚未声明

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

我的log.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()函数......

,将编译此代码

2 个答案:

答案 0 :(得分:10)

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

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

答案 1 :(得分:1)

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