3

I can't figure out why this example code doesn't work right. My compiler says that the functions being called are not members of the declared namespace. This is the example code for Boost log so why doesn't it work? What do I need to do?

I've already defined BOOST_LOG_DYN_LINK, and I have all of the headers included, that should need to be included. Additionally boost was installed via yum from the fedora repos, according to yum, the boost version is 1.55.0.

Example: http://www.boost.org/doc/libs/1_55_0/libs/log/example/doc/tutorial_file.cpp

Errors

main.cpp:33:5: error: ‘add_file_log’ is not a member of ‘logging’
     logging::add_file_log(
     ^
main.cpp:34:10: error: ‘file_name’ is not a member of ‘keywords’
          keywords::file_name = "sample_%N.log",                                        /*< file name pattern >*/
          ^
main.cpp:35:10: error: ‘rotation_size’ is not a member of ‘keywords’
          keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
          ^
main.cpp:36:10: error: ‘time_based_rotation’ is not a member of ‘keywords’
          keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
          ^
main.cpp:36:49: error: ‘sinks::file’ has not been declared
          keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/

Code

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;

void init()
{
    logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",
        keywords::rotation_size = 10 * 1024 * 1024,
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
        keywords::format = "[%TimeStamp%]: %Message%"
    );

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

Make invocation

g++ -c -DBOOST_LOG_DYN_LINK -o main.cpp.o main.cpp

Linker flags: -lboost_program_options -lboost_log -lboost_filesystem -lboost_system -lboost_thread -lpthread

Verbose Log: https://gist.github.com/HSchmale16/d4dd5656a47ce82c63b2

HSchmale
  • 1,838
  • 2
  • 21
  • 48

2 Answers2

1

Check your header files for anything missing and also include -lboost_log_setup to your compiler/linker invocation.

Tasos Vogiatzoglou
  • 2,393
  • 12
  • 16
0

I can compile this with no errors, no changes to the code. Check your boost::log source to be sure you have what you expect to have. My guess is your boost files have been corrupted. Trust that this error indicates the function isn't found where the compiler is looking.

Algonaut
  • 349
  • 4
  • 7
  • I've checked for corruption, and that did not occur. I downloaded the boost headers directly from the fedora repos via `yum`, and I reinstalled all of boost and it still occurs – HSchmale May 03 '15 at 17:13
  • Try to see if the included code is actually what is intended to be included. You can run preprocessor on the code by passing -E instead of -c in the compiler command line and then see if the preprocessed output actually contains the referenced symbols. – Andrey Semashev May 04 '15 at 16:16