1

I'm trying to compile this simple program to start learning how to use timers:

#include <boost/timer.hpp>

using boost::timer::cpu_timer;
//...
nanosecond_type last_checkpoint_time = 0;
cpu_timer checkpoint_timer;  // start the timer

for (;;)
{
  //process_a_transaction();
  if (checkpoint_timer.elapsed().user - last_checkpoint_time > 5*1000000000LL)
  {
    //... create a checkpoint ...
    last_checkpoint_time = checkpoint_timer.elapsed().user;  
    cout << checkpoint_timer.elapsed().user << endl;
  }
}

I'm using gentoo linux and issuing the following command to compile:

g++ -I /usr/include/boost-1_46 timer1.cpp -o timer

I get these errors:

timer1.cpp:3:21: error: ‘boost::timer::cpu_timer’ has not been declared
timer1.cpp:5:1: error: ‘nanosecond_type’ does not name a type
timer1.cpp:6:1: error: ‘cpu_timer’ does not name a type
timer1.cpp:8:1: error: expected unqualified-id before ‘for’
timer1.cpp:8:8: error: expected unqualified-id before ‘)’ token

I was reading the docs under errors and warnings but the problem I am having is that I only have two libraries:

/usr/lib/libboost_test_exec_monitor-1_46.a
/usr/lib/libboost_test_exec_monitor-mt-1_46.a

Is this because I did not use the static-libs flag during compile of boost? Would I be better off using static-libs? Maybe this is a tangent. What else can cause the errors given above? Please forgive my ignorance as I am pretty new to C++/boost.

Thanks

nomadicME
  • 1,389
  • 5
  • 15
  • 35

3 Answers3

3

I haven't been using cpu_timer my self, but a quick Google search seems to indicate you should include <boost/timer/timer.hpp> instead. As for the error of nanosecond_type you need to use another using statement for that.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • thank you for your quick reply. I actually started with that include statement, but I was getting this error: timer1.cpp:1:33: fatal error: boost/timer/timer.hpp: No such file or directory, so I found where timer.hpp lives and it is in: /usr/include/boost-1_46/boost/timer.hpp, so that is when I changed my include line to the one provided in my original post. That cleared up the no such file or directory problem. So I don't think that is it. – nomadicME Mar 18 '12 at 03:05
1

I think I figured out what the problem is. I was quoting an example in my original post from the ver 1.49 documentation. cpu_timer was first discussed in the boost documentation in ver 1.48. The stable version on gentoo is currently 1.46 and testing only provides ver 1.47, ver 1.48 is hardmasked. So my only option is to remove boost from my system download the tar of 1.49 and possibly break my system wrt boost or wait for the hardmask to be removed from ver 1.48.

nomadicME
  • 1,389
  • 5
  • 15
  • 35
0

In any case, static-libs is certainly irrelevant because this is a compiler error, not a linker error. It doesn't look at the libraries until the linker stage, until then only the headers are relevant.

Chewi
  • 530
  • 3
  • 4