Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8664313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:12:46+00:00 2026-06-12T17:12:46+00:00

I want to to use boost auto_cpu_timer to display the time my complete code

  • 0

I want to to use boost auto_cpu_timer to display the time my complete code needs to run. Additionally i want to see the progress of my loops using progress_display.

It seems there is a namespace confilict as Boost has two timer classes, where progress_display is from the old, now deprecated library.

http://www.boost.org/doc/libs/1_51_0/libs/timer/doc/index.html

Still, is there a way to achieve this? The following example shows, what i’m trying to do. Using either AUTO or PROG works fine, but both together result in error messages.

Main: compiled with g++ -lboost_timer main.cc -o time

#define AUTO
#define PROG

#ifdef  PROG
#include <boost/progress.hpp>
#endif     //----  PROG  -----

#ifdef  AUTO
#include <boost/timer/timer.hpp>
#endif     //----  AUTO  -----

#include <cmath>

int main()
{
#ifdef  AUTO
    boost::timer::auto_cpu_timer t;
#endif     //----  AUTO  -----

    long loops = 100000000;

#ifdef  PROG
    boost::progress_display pd( loops );
#endif     //----  PROG  -----

    //long loop to burn some time
    for (long i = 0; i < loops; ++i)
    {
        std::sqrt(123.456L);
#ifdef  PROG
        ++pd;
#endif     //----  PROG  -----
    }

    return 0;
}

Error log:

/usr/include/boost/timer/timer.hpp:38:1: error: ‘namespace boost::timer { }’ redeclared as different kind of symbol
/usr/include/boost/timer.hpp:45:1: error: previous declaration of ‘class boost::timer’
/usr/include/boost/timer/timer.hpp: In member function ‘std::string boost::timer::cpu_timer::format(short int, const std::string&) const’:
/usr/include/boost/timer/timer.hpp:74:34: error: ‘format’ is not a member of ‘boost::timer’
/usr/include/boost/timer/timer.hpp: In member function ‘std::string boost::timer::cpu_timer::format(short int) const’:
/usr/include/boost/timer/timer.hpp:76:34: error: ‘format’ is not a member of ‘boost::timer’
main.cc: In function ‘int main()’:
main.cc:17:2: error: ‘auto_cpu_timer’ is not a member of ‘boost::timer’
main.cc:17:31: error: expected ‘;’ before ‘t’
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:12:47+00:00Added an answer on June 12, 2026 at 5:12 pm

    When you include boost/progress.hpp, the C++ compiler sees a definition for boost::timer as class timer defined in boost/timer.hpp that is included in boost/progress.hpp.

    When you include boost/time/timer.hpp, the C++ compiler sees another definition for boost::timer as a namespace and this is the cause of the error.

    If you really want to use it, the solution is renaming one of those boost::timer through macro. But because namespace boost::timer contains functions that are implemented outside of the header (like std::string format(const cpu_times& times, short places, const std::string& format)) you must rename class boost::timer. So your code will be something like this:

    #ifdef  PROG
    #define timer   timer_class
    #include <boost/progress.hpp>
    #undef timer
    #endif     //----  PROG  -----
    
    #ifdef  AUTO
    #include <boost/timer/timer.hpp>
    #endif     //----  AUTO  -----
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using boost build in my project and now i want to use
I want use this 1 for using Bar code or QR code scanner. I
I want to use boost::crc so that it works exactly like PHP's crc32() function.
I want to use boost::timed_wait to wait for an event or to timeout after
We use Boost statically linked with our app but now I want to use
I want to use boost::thread_specific_ptr but need to know what to add to my
I want to start using smart pointers in my code but I don't really
I want to use boost::bind (I'm not sure if it is really the right
I want to use boost::asio but I don't want boost to throw exceptions, because
I want to use the boost library in a c++ project I'm doing in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.