Sign in to follow this  
lride

Having trouble compiling C++11 chrono with CodeBlocks, MinGW

Recommended Posts

lride    674
I just installed code blocks and latest mingw today
The following code compiles fine on MSVS2012, but not on code blocks
[source lang="cpp"]#ifndef TIMER_H
#define TIMER_H

#include <chrono>
class Timer
{
private:
std::chrono::steady_clock::time_point startTime;
public:
Timer::Timer(): startTime(std::chrono::steady_clock::now()){}

~Timer(){}

typedef std::chrono::duration<double> sec;

double Timer::getElapsedTime()
{
return std::chrono::duration_cast<sec>(std::chrono::steady_clock::now()-startTime).count();
}
void Timer::restart()
{
startTime=std::chrono::steady_clock::now();
}
};

#endif // TIMER_H
[/source]
errors I get:

mingw32-g++.exe -Wall -O3 -O2 -std=c++0x -I"..\MinGW compiler test" -c "C:\Users\Park\Desktop\MinGW compiler test\main.cpp" -o obj\Release\main.o
In file included from C:\Users\Park\Desktop\MinGW compiler test\main.cpp:5:0:
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:8:2: error: 'steady_clock' in namespace 'std::chrono' does not name a type
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:10:2: error: extra qualification 'Timer::' on member 'Timer' [-fpermissive]
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:16:9: error: extra qualification 'Timer::' on member 'getElapsedTime' [-fpermissive]
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:20:7: error: extra qualification 'Timer::' on member 'restart' [-fpermissive]
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h: In constructor 'Timer::Timer()':
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:10:18: error: class 'Timer' does not have any field named 'startTime'
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:10:41: error: 'std::chrono::steady_clock' has not been declared
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h: In member function 'double Timer::getElapsedTime()':
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:18:55: error: 'std::chrono::steady_clock' has not been declared
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:18:75: error: 'startTime' was not declared in this scope
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h: In member function 'void Timer::restart()':
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:22:3: error: 'startTime' was not declared in this scope
C:\Users\Park\Desktop\MinGW compiler test\/include/Timer.h:22:26: error: 'std::chrono::steady_clock' has not been declared
C:\Users\Park\Desktop\MinGW compiler test\main.cpp: In function 'int main()':

Share this post


Link to post
Share on other sites
lride    674
[quote name='CyberRascal' timestamp='1354472093' post='5006335']
Really? Exactly that code? Chrono is in boost namespace..
[/quote]

I'm using std::chrono(c++11), not boost::chrono.
This compiled fine with MSVC 2012...

Share this post


Link to post
Share on other sites
the_edd    2109
I would guess that the version of the C++ standard library that comes with Code::Blocks is not sufficiently recent. You could try to upgrade to the latest MinGW release, after researching whether or not it provides the std::chrono stuff.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this