2

I use Qt 5.9.1 and all works fine. Except of one little nuisance: it overrides my -std=C++17.

The project:

#CONFIG += c++14 #makes -std=gnu++1y 
#CONFIG += c++17  # is not supported by Qt591
QMAKE_CXXFLAGS += -std=c++17
TARGET = equipment
TEMPLATE = app
SOURCES += ....
....

Compile instructions:

g++ -c -pipe -std=c++17 -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC
-DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_SERIALPORT_LIB -DQT_CORE_LIB  
-I../app -I/opt/Qt5.9.1/5.9.1/gcc_64/include -I/opt/Qt5.9.1/5.9.1/gcc_64
/include/QtCore -I. -I/opt/Qt5.9.1/5.9.1/gcc_64/mkspecs/linux-g++ 
-o test0.o ../test0.cc

We can see two -std= and the second -std=gnu++11 by QMake overrides mine first -std=c++17.

How can I tell QMake to use -std=C++17?

kyb
  • 7,233
  • 5
  • 52
  • 105
  • 1
    I just read https://forum.qt.io/topic/11565/qmake_cxxflags-overriden/2 : maybe using `QMAKE_CXXFLAGS_WARN_ON` instead of `QMAKE_CXXFLAGS` whould make your flag override the other... – Olivier Sohn Jul 05 '18 at 17:28
  • 1
    Possible duplicate of [Can't use c++17 features using g++ 7.2 in QtCreator](https://stackoverflow.com/questions/46610996/cant-use-c17-features-using-g-7-2-in-qtcreator) – jonspaceharper Jul 13 '18 at 23:46

2 Answers2

3

Try CONFIG += c++1z and if it doesn't work pass it to compiler with QMAKE_CXXFLAG.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
Timur Kukharskiy
  • 303
  • 3
  • 16
0

I'm facing a similar problem. But the reason was that pkg-config included the dependency flag of the target library (-std=с++11). For the g++ compiler, the last flag has the highest priority. And qmake adds library flags and their dependencies after yours.

megorit
  • 101
  • 3