2011-05-19 137 views
2

谁能告诉我我做错了什么?C++ boost日志编译错误(linux)

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

# c++ -I /var/local/boost_1_46_1/ log.cpp -o log -lboost-log
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

我也试过它明确地从两个阶段链接库和/ 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()功能这个代码将编译...

回答

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

+0

我仍然收到错误,我将使用我所做的更改更新原始帖子。 – suhprano 2011-05-19 19:13:56

+1

我的不好,教程重新定义了命名空间。我会编辑我的答案。 – 2011-05-19 19:22:36

+0

真棒,感谢您的帮助。 – suhprano 2011-05-19 19:32:47

1

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

+0

雅,有2个core.hpps,一个升压/日志和一个升压/日志/核心。我上面包含的一个core.hpp包含了另一个像这样的: #include #include suhprano 2011-05-19 18:01:23