GaryTang
GaryTang

Reputation: 11

Can't compile simple C++ code using boost trivial log with filters

I am trying to use boost log with simple code from: http://www.boost.org/doc/libs/1_58_0/libs/log/doc/html/log/tutorial/trivial_filtering.html. I am using codeblock 13.12 on Windows 8.1 with cpu: AMD-A8. Code is below:

#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>

using namespace std;

void init()
{
    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}

int main()
{
    init();
    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";

    return 0;
}

The error message is: C:\Java\boost_1_55_0/boost/smart_ptr/detail/sp_convertible.hpp: In instantiation of 'struct boost::detail::sp_enable_if_convertible': C:\Java\boost_1_55_0/boost/smart_ptr/intrusive_ptr.hpp:76:5: required by substitution of 'template boost::intrusive_ptr::intrusive_ptr(const boost::intrusive_ptr&, typename boost::detail::sp_enable_if_convertible::type) [with U = boost::log::v2s_mt_nt5::attribute_value::impl]' C:\Java\boost_1_55_0/boost/log/attributes/attribute_value.hpp:95:20: required from here C:\Java\boost_1_55_0/boost/smart_ptr/detail/sp_convertible.hpp:81:37: warning: base class 'struct boost::detail::sp_enable_if_convertible_impl' has a non-virtual destructor [-Weffc++] In file included from C:\Java\boost_1_55_0/boost/log/attributes/attribute_value_set.hpp:27:0, from C:\Java\boost_1_55_0/boost/log/core/record.hpp:21, from C:\Java\boost_1_55_0/boost/log/core/core.hpp:23, from C:\Java\boost_1_55_0/boost/log/core.hpp:20, from C:\Workspace\FileReconciliation\main.cpp:3:

The command CodeBlock used to compile is: mingw32-g++.exe -Weffc++ -std=c++11 -Wall -fexceptions -Weffc++ -pedantic -g -IC:\Java\boost_1_55_0 -Iinclude -c C:\Workspace\FileReconciliation\main.cpp -o obj\Debug\main.o

Regardless where I put this include:

#include <boost/smart_ptr/intrusive_ptr.hpp>

It always give me the same error message. I tried boost 1_55_0, 1_59_0 and 1_60_0. If I remove init(), it compiles without error.

I googled a lot and can't find an answer. Could someone please help? Thanks a lot gt

Upvotes: 0

Views: 810

Answers (2)

GaryTang
GaryTang

Reputation: 11

I fixed the problem by using: "-std=gnu++11", instead of "-std=c++11". It took me a few days...

Upvotes: 0

Garland
Garland

Reputation: 921

Missing namespace definition for logging.

You will need the following statement after the #include code block.

// Alias for shorter namespaces.
namespace logging = boost::log;

Upvotes: 0

Related Questions