5

I had issues a while back getting std::variant to work in a QtCreator project, facing similar complaints here:

Can't use c++17 features using g++ 7.2 in QtCreator

I resolved this issue, and have been happily working on this project for some time with no further issues. This was running on ubuntu 14.04, built with GCC 7.2.0, and built under clang 5.0 aswell.

Two days ago I backed everything up, installed the latest QtCreator, installed all my tools again (gcc 7.2.0 and clang 5.0) retrieved my project and tried to build. The build fails, stating:

/usr/include/c++/7.2.0/bits/c++17_warning.h:32: error: This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.

In my project file, I already have this:

QMAKE_CXXFLAGS += -std=c++17

And I can see in the phrase "-std=c++17" in the compiler output. Here is the complete compiler output up until the first error:

15:08:37: Running steps for project AIRadioQt...
15:08:37: Skipping disabled step qmake.
15:08:37: Starting: "/usr/bin/make" 
/home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake -o Makefile ../AIRadioQt/AIRadioQt.pro -spec linux-clang CONFIG+=debug CONFIG+=qml_debug
clang++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIRadioQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Programming/Qt/5.10.0/gcc_64/include -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtDataVisualization -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtWidgets -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtGui -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang -o main.o ../AIRadioQt/main.cpp
In file included from ../AIRadioQt/main.cpp:1:
In file included from ../AIRadioQt/stdafx.h:9:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/variant:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/c++17_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2017 standard. This support must be enabled with the -std=c++17 or -std=gnu++17 compiler options.
#error This file requires compiler and library support \
 ^

So, as you can see, the -std=c++17 flag is set. Is there an issue with flag order here?

The next curious thing is that whether I use my gcc kit or clang kit in QtCreator, it always seems to call clang in the compiler output, shown in this line:

clang++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../AIRadioQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -I../../../../Programming/Qt/5.10.0/gcc_64/include -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtDataVisualization -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtWidgets -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtGui -I../../../../Programming/Qt/5.10.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I. -I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang -o main.o ../AIRadioQt/main.cpp

and it mentions clang again near the end of that line with this include flag:

-I../../../../Programming/Qt/5.10.0/gcc_64/mkspecs/linux-clang

I have quadruple checked up kits, and the GCC one definitely calls GCC and GCC++, and the Clang one definitely calls Clang and Clang++. I have checked the executable links and followed their link paths step by step, /usr/bin/gcc definitely links to /usr/bin/x86_64-linux-gnu-gcc-7 and /usr/bin/g++ definitely links to /usr/bin/x86_64-linux-gnu-g++-7. So I am baffled as to why it insists on calling Clang instead of GCC when I have the GCC kit selected! Regardless, my versions of both GCC and Clang support c++17, so this should not be the cause of my issues anyway should it?

Iron Attorney
  • 1,003
  • 1
  • 9
  • 22
  • 3
    `-std=gnu++11` appears *after* `-std=gnu++17` on the command line. Maybe it overrides it? – Galik Dec 21 '17 at 16:04
  • Ok, didn't know if you had it *exactly* like they had it. I will remove my flag. I thought something small in that question might have fixed it. – gsquaredxc Dec 21 '17 at 16:08
  • @Galik maybe if it was `-std=gnu++17` it would be fixed? I am not sure, I typically don't use QtCreator. – gsquaredxc Dec 21 '17 at 16:11
  • @Galik I was wondering something Similar. Is that how this works? Should it ideally only show one flag? My QtCreator project file only mentions the c++17 flag, is there an option somewhere else in QtCreator or my toolkit setup that might add an extra flag? – Iron Attorney Dec 21 '17 at 16:11
  • I would guess the last flag wins. – Galik Dec 21 '17 at 16:12
  • @GrantGarrison The error message suggests both should work, but gave it a shot anyway, no change. – Iron Attorney Dec 21 '17 at 16:14
  • @Galik alright, I'll investigate if there is another setting somewhere adding this extra flag. Looking back at my original problem (the question I link to at the top of this question), before I got the c++17 flag working, I had no c++xx flags listed in the compiler output at all. So maybe my new QtCreator or my compiler toolkit setups are adding something in – Iron Attorney Dec 21 '17 at 16:17
  • So heres something pretty weird. When I'm building under Debug, It doesn't matter if I chose my GCC or Clang kit, it always builds with Clang and adds the flag "-std=gnu++11" after the flag added from my project file. However, if I switch to Release, then changing to the GCC kit DOES call GCC instead of Clang, and the compiler output does NOT have the additional "-std=gnu++11" flag, and the error disappears. This is pretty bloody strange. I can't find any mistakes in my Kit setup that would cause the Clang glitch with the Debug build, and I can't find anything that might cause the extra flag – Iron Attorney Dec 21 '17 at 16:40
  • Any QtCreator users have any ideas here? Or should I open a new question? – Iron Attorney Dec 21 '17 at 16:40

1 Answers1

4

As Galik pointed out above, the compiler flag "-std=gnu++11" comes after the flag "-std=c++17" and therefor overrides it, which is the cause of this error.

This appearance of this extra flag in my compiler output is however currently a mystery. It only appears when building with Clang, not with GCC, and for some reason QtCreator is building with Clang when selecting any of the following kits:

Clang Release, Clang Debug, GCC Debug.

But not when using this kit:

GCC Release.

I have checked the options and toolkit setups thoroughly, and I can't see any errors, so I will open a new more appropriate question for these issues and I will post links in my original question when they are answered in case anyone else reading my question also has these problems.

Iron Attorney
  • 1,003
  • 1
  • 9
  • 22