Solved

I could not build boost code,

Posted on 2016-09-29
10
124 Views
Last Modified: 2016-10-04
I have sample code, I just wanted to build it. I am trying to send log to a file, unfortunately the init function part does not compile, I posted code and compile error as follows, I just wonder what I did wrong here:
Thanks for your help.

Here is the code I am compiling, boost has setup correctly, I can build main part, it running and output message on the console, I just need to redirect to a file, but I could not build init() function:

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>

using namespace boost::log;

void init()
{
    logging::add_file_log("sample.log");

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= 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";

	return 0;
}

Open in new window

Here is the compile output:


1>------ Build started: Project: testboostLogging, Configuration: Debug x64 ------
1>Build started 9/29/2016 7:35:19 AM.
1>InitializeBuildStatus:
1>  Touching "x64\Debug\testboostLogging.unsuccessfulbuild".
1>ClCompile:
1>  testboostLogging.cpp
1>testboostLogging.cpp(13): error C2653: 'logging' : is not a class or namespace name
1>testboostLogging.cpp(15): error C2653: 'logging' : is not a class or namespace name
1>testboostLogging.cpp(16): error C2227: left of '->set_filter' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>testboostLogging.cpp(17): error C2653: 'logging' : is not a class or namespace name
1>testboostLogging.cpp(17): error C2065: 'severity' : undeclared identifier
1>testboostLogging.cpp(17): error C2653: 'logging' : is not a class or namespace name
1>testboostLogging.cpp(18): error C2065: 'info' : undeclared identifier
1>testboostLogging.cpp(15): error C3861: 'get': identifier not found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:22.41
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am using boost 1.59.0 at this time, I have compiled the code for both 64 bit.
Does anyone knows what is wrong?

Evan
0
Comment
Question by:Evan Li
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 41822992
Hi Evan Li,

well, the first error does clearly show what the problem is:

testboostLogging.cpp(13): error C2653: 'logging' : is not a class or namespace name

Most (if not all) Boost functions/classes you use are declared in namespace boost::log, there's no namespace boost::log::logging, so to solve the compile errors it should be enout to remove all occurances of logging:: from your code.

Hope that helps,

ZOPPO
0
 

Author Comment

by:Evan Li
ID: 41823822
Thank you very much,

I added following line:
namespace logging = boost::log;

This makes it to be build.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 41824517
Hm - why do you want to delete this question? Didn't my comment correctly identify the problem you had?

ZOPPO
1
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Evan Li
ID: 41825491
Yes, your comment helps. Thank you. Let me make your comment to be the best solution.
0
 

Author Comment

by:Evan Li
ID: 41825497
There is no way I can do it again.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 41825934
Hi Evan Li,

here you can find how to handle cases like There was a mistake made when closing the question and awarding points: http://support.experts-exchange.com/customer/portal/articles/539391-the-request-attention-system 

Best regards,

ZOPPO
0
 

Author Comment

by:Evan Li
ID: 41827252
If you disagree with the way a question you participated in was closed, you can either post an Objection or Request Attention, depending on how the question was closed.
Can you post objection?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 41827627
@Moderator: We agreed to not delete this question, could you please re-open it so Evan Li can select #a41822992 as answer?
0
 

Author Closing Comment

by:Evan Li
ID: 41828423
Thanks. Close this question here
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question