10

I am having trouble compiling with chrono, here is the code:

Time.hh

#include        <chrono>

class           Time
{
protected:
  std::chrono::steady_clock::time_point _start_t;
  std::chrono::steady_clock::time_point _now;
  std::chrono::steady_clock::time_point _time;
public:
  Time();
  Time(const Time &other);
  Time          &operator=(const Time &other);
  ~Time();
public:
  void          start();
  double        getDurSec();
  double        getDurMilSec();
private:
  void          setNow();
};

Compilation error:

g++  -W -Wall -Wextra -I./include -std=c++0x  -c -o src/Time/Time.o src/Time/Time.cpp
In file included from src/Time/Time.cpp:11:0:
./include/Time/Time.hh:21:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not     name a type
./include/Time/Time.hh:22:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not name a type
./include/Time/Time.hh:23:3: error: ‘steady_clock’ in namespace ‘std::chrono’ does not name a type
src/Time/Time.cpp: In member function ‘void Time::start()’:
src/Time/Time.cpp:34:2: error: ‘_time’ was not declared in this scope
src/Time/Time.cpp:34:23: error: ‘std::chrono::steady_clock’ has not been declared

Etc...

Tell me if you need more informations.

gsamaras
  • 71,951
  • 46
  • 188
  • 305

1 Answers1

13

You are probably using a g++ version prior to 4.7.0 where std::chrono::steady_clock was not implemented. If this is the case, you have two solutions:

  • Upgrade your g++ to 4.7.0 or a more recent version.
  • Use instead the old std::chrono::monotonic_clock.
Jehan
  • 746
  • 5
  • 13
  • [12:09]camill_a@/home/camill_a[4]$ g++ -v [...] gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) –  May 13 '13 at 10:10
  • Is g++4.7 a wide used version? Is this stable? I am currently installing it this way http://askubuntu.com/questions/168947/how-to-upgrade-g-to-4-7-1 –  May 13 '13 at 10:17
  • And a last comment, what are the differences betwin monotonic and steady? –  May 13 '13 at 10:18
  • Ok finally I used monotonic instead of steady. Thanks a lot Jehan. –  May 13 '13 at 10:34
  • @Mayerz g++ 4.7.3 is currently the oldest maintained version. g++ 4.8.0 has already been released, and g++ 4.8.1 and 4.9.0 are in progress. I think you can safely say that g++ 4.7.3 is a stable release. – Jehan May 13 '13 at 10:51
  • Yhea I sadly discovered this 10 minutes ago! But this is a school project, and it have to be runned on school distro, and they use version 4.6.2 or something like that... So I will just be using monotonic, and my mates will have to downgrade their archlinux g++ down to the unmaintained version. This is funny. –  May 13 '13 at 10:55
  • 3
    @Mayerz Consider yourself lucky. My school still uses g++ 3.4 :) – Jehan May 13 '13 at 11:03
  • 4
    @Mayerz - `monotonic_clock` was in early drafts of the `chrono` specification. It was replaced by `steady_clock`, which has more useful semantics. – Pete Becker May 13 '13 at 15:23