Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Compiler requesting c++17 support to be enabled for std::variant by using the -std++17 flag when -std=c++17 is in compiler output

Ask Question

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?

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, 2017 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, 2017 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, 2017 at 16:11

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.

I also remember "-std=gnu++11 flag sprinkling out of nowhere on Windows/Clang. Unfortunately, I also haven't found its cause. – arrowd Dec 21, 2017 at 17:24 Bizzar! What IDE were you using? If I come up with a solution or at least a reason for it, I'll make sure I link you to it – Iron Attorney Dec 21, 2017 at 17:29

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.