2011-05-19 140 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