C++11 with MinGW

Using standard MinGW (cc 4.9.3), I couldn’t compile C++11 test programs without lots of errors.  The answer: use -std=gnu++11 rather than -std=c++11.  Obvious, right?…

Test program:

#include <memory>
#include <iostream>
using namespace std;
int main()
{
    shared_ptr<int> x(new int(42));
    cout << (*x) << endl;
    return 0;
}

Error messages with “c++11”:

$ g++ --std=c++11 -o test test.cpp 
In file included from c:\mingw\include\wchar.h:208:0, 
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\cwchar:44, 
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\bits\postypes.h:40,
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\iosfwd:40,
  from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\memory:72, from test.cpp:1: 
c:\mingw\include\sys/stat.h:173:14: error: '_dev_t' does not name a type 
struct _stat __struct_stat_defined( _off_t, time_t ); 
             ^

and many, many more (444 lines total).

By contrast:

$ g++ --std=gnu++11 -o test test.cpp
$ ./test.exe
42
$

Much better!

Exercise for the reader: try TDM-GCC and tell me in the comments whether it works with c++11.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s