1

I am using MSys2/MinGW on Windows 7 to build an old project. MSys2 only uses the latest version of gcc and building the project with gcc v9.1.0 fails because it can't find an overloaded "<<" operator.

Through trial and error (and Cygwin), I have found that gcc v6.4.0 builds the project and v7.x does not.

Is there a CCFLAGS or CXXFLAGS option that I can use to make gcc v9.1.0 behave as if it was v6.4.0?

Iain Waugh
  • 75
  • 5
  • Wouldn't it be better to find out Why _it can't find an overloaded "<<" operator_ and fix the problem? It might be caused by hidden [U.B.](https://stackoverflow.com/a/4105123/1505939) in code which only accidentally worked in the older compiler. (I had such a case when we switched from VS2008 to VS2013. The actual reason was wrong use of a `std::set` which was uncovered in the newer compiler (where it simply failed to compile).) – Scheff's Cat Jul 23 '19 at 05:18
  • Technically, yes. We have managed to get past this problem with a Cygwin build, but I'd like to solve the build error in a way that does not alter the source files. If no gcc flags exist for this purpose, then the source code will be updated. – Iain Waugh Jul 23 '19 at 05:37
  • Have you tried to change the C++ standard by using command line arg. `-std`? May be, it's worth to expose the actual error message for the not found `operator<<`. Is it one of the `std` library or a custom? – Scheff's Cat Jul 23 '19 at 05:39
  • Yes. There is a `-std=c++11` flag in the CXXFLAGS. – Iain Waugh Jul 23 '19 at 05:48
  • It's a custom template, which refers to an overloaded method further down the same file. I can't provide the example, unfortunately. – Iain Waugh Jul 23 '19 at 05:49
  • _I can't provide the example, unfortunately._ That's wrong. You don't need to expose your code. (You shouldn't.) Just resemble the issue in a [mcve]. – Scheff's Cat Jul 23 '19 at 05:50

2 Answers2

0

It appears as if this cannot be solved with compiler flags, so the answer to the question is "no".

Workaround: If you are in a position where you cannot modify the source code and you're compiling under Windows, then download a specific version of the MinGW toolchain using the MinGW Installer Utility from here. This lets you choose which version of GCC to install.

You can still use an MSys/MinGW shell if you change your PATH variable to put the new MinGW install directory first by adding a line like this to your .profile:

export PATH=/c/mingw-w64/x86_64-6.4.0-win32/mingw64/bin:$PATH

Iain Waugh
  • 75
  • 5
0

You can tell GCC to use an older C/C++ standard using the -std= compiler flag, for example the g++ option -std=c++11 to make it conform to to the ISO 2011 C++ standard.

To get a list of all possible -std= command line flags run:

g++ --help -v 2>/dev/null|grep std=

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40