0

I'm using the gcc compiler on Windows with MinGW. Version is 4.9.3. The following code gives errors when -std=c++98, -std=c++03 or -std=c++11 is used as an argument.

#include <iostream>

int main()
{
    std::cout << "Hello world!" << std::endl;
    return 0;
}

The code compiles with no errors when -std=gnu++98, -std=gnu++03 or std=gnu++11 is used as an argument. Also, the code compiles with no errors when using no c++ version arguments (g++ test.cpp -c)

On further investigation I found it was the #include causing issues. This code produces no errors when using any of the std=c++ arguments:

int main()
{
    return 0;
}

However, when looking for other things to include to test my code, the following works:

#include <cmath>
int main()
{
    return 0;
}

but this doesn't:

#include <string>
int main()
{
    return 0;
}

What's going on? From a brief search on gnu++, it says that it provides additional extensions but code as simple as the ones above surely shouldn't be reliant on any extensions?

I've pasted the large error which occurs when compiling the first piece of code with g++ test.cpp -c -std=c++11. http://pastebin.com/k0RLtWQz

The first messages are:

$ g++ test.cpp -c -std=c++11
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++\ios:38,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\iostream:39,
                 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 );
              ^
c:\mingw\include\sys/stat.h:173:14: error: '_ino_t' does not name a type
 struct _stat __struct_stat_defined( _off_t, time_t );
              ^
…
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
ratorx
  • 257
  • 1
  • 8
  • 1
    That should not happen, looks like your installation is broken. (Also, it's old.) Did you try reinstalling? – Baum mit Augen Aug 10 '16 at 17:04
  • related/dupe: http://stackoverflow.com/questions/38538924/g-updated-on-mingw-gets-massive-error-messages – NathanOliver Aug 10 '16 at 17:10
  • 1
    Given the first two error messages, there is something amiss with your installation. On a Unix system, it would be as if the `` header was not functioning. Think seriously about whether to reinstall — that may be the easiest way to fix the problem. Otherwise, you're down to tracking which header isn't defining `_ino_t` and `_dev_t` that should, and why it doesn't when compiling with strict C++. It might be a bug in the system. Can you upgrade from GCC 4.9.3 to, say, 6.1.0? (GCC 4.9.4 was released 2016-08-03 as the last 4.9.x version. GCC 5.4 was released at the same time.) – Jonathan Leffler Aug 10 '16 at 17:11
  • @Baum mit Augen I'll try running the mingw update again although I did it before the trying to compile this. If my installation was proken, surely it would never compile? My program does compile, just not when using any of the -std=c++xx arguments. – ratorx Aug 10 '16 at 17:11
  • @BaummitAugen But he says that: "I'm using the gcc compiler on Windows with MinGW." – Rakete1111 Aug 10 '16 at 17:11
  • @ratorx Well, it doesn't compile with the standard flags although it should, looks pretty broken to me. :) – Baum mit Augen Aug 10 '16 at 17:12
  • @Nathanoliver I know that it works when using -std=gnu++xx, but my question is more about why that's the case, because surely nothing in my code is improper c++? – ratorx Aug 10 '16 at 17:13
  • 1
    There's a chain of questions linked to from [SO 38538924](http://stackoverflow.com/q/38538924) suggested by NathanOliver with the same symptoms. There's nothing wrong with your source code; it is, as you say, correct. There's a bug of some sort with the MinGW installation or with the distribution (the installation reflects what was distributed but what was distributed is itself faulty). You might need to review the `c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\bits\postypes.h` file to see what's going wrong — or other files in the chain, or other files included (try `-H` to see the headers). – Jonathan Leffler Aug 10 '16 at 17:23

1 Answers1

0

Solved by changing to mingw64 (which also uses a newer version of gcc). Seems like the problem was with either my mingw32 installation or with the distribution (as pointed out by Jonathan Leffler). All the -std=c++xx parameters now work.

ratorx
  • 257
  • 1
  • 8