C++ boost logging compile error (linux)
Can anyone tell me what I'm doing wrong?
Running this on the console yields the following error:
log.cpp: In function âvoid init()â: log.cpp:11: error: âboost::loggingâ has not been declared log.cpp:13: error: âboost::fltâ has not been declared log.cpp:13: error: âloggingâ has not been declared log.cpp:13: error: âloggingâ has not been declared
#
c++ -I /var/local/boost_1_46_1/ log.cpp -o log -lboost-log
I've also tried it explicitly linking the libraries from both stage and /usr/local/lib directories.
My 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
);
}
}
in开发者_开发问答t 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";
}
This code will compile if I leave out the void init()
function...
You need the following namespace redefinitions to use the tutorials:
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
Are you sure your #include
is right? Try #include <boost/log/core/core.hpp>
.
精彩评论