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()':
Having trouble compiling C++11 chrono with CodeBlocks, MinGW
Really? Exactly that code? Chrono is in boost namespace..
I'm using std::chrono(c++11), not boost::chrono.
This compiled fine with MSVC 2012...
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement