Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 1995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement

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...

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!