I am using QtCreator, Qt 5.10, and trying to use c++17 in a project that worked perfectly until I did a clean install of latest Ubuntu and reinstalled everything.
Now, when clang is called to build the project (which happens for some reason with my Clang Relase, Clang Debug and GCC Debug builds...) I get this extra compiler flag after the ones added from my .pro file:
-std=gnu++11
This does not happen when building with my GCC Release kit (the one which actually calls the gcc compiler instead of clang). This extra flag overides the earlier flag:
-std=c++17
...which is added because of the line in my .pro file:
QMAKE_CXXFLAGS += -std=c++17
I have looked at the makefile for each build, here is the Makefile for the Clang Release build:
#############################################################################
# Makefile for building: AIRadioQt
# Generated by qmake (3.1) (Qt 5.10.0)
# Project: ../AIRadioQt/AIRadioQt.pro
# Template: app
# Command: /home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake -o Makefile ../AIRadioQt/AIRadioQt.pro -spec linux-clang
#############################################################################
MAKEFILE = Makefile
####### Compiler, tools and options
CC = clang
CXX = clang++
DEFINES = -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_DATAVISUALIZATION_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS = -pipe -std=c++17 -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH = -I../AIRadioQt -I. -I../src -I../src/AIBase -I../src/Maths -I../src/Random -isystem /usr/local/include/csound -isystem /usr/include/GL -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
QMAKE = /home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake
DEL_FILE = rm -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
COPY = cp -f
COPY_FILE = cp -f
COPY_DIR = cp -f -R
INSTALL_FILE = install -m 644 -p
INSTALL_PROGRAM = install -m 755 -p
INSTALL_DIR = cp -f -R
QINSTALL = /home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake -install qinstall
QINSTALL_PROGRAM = /home/pete/Programming/Qt/5.10.0/gcc_64/bin/qmake -install qinstall -exe
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
TAR = tar -cf
COMPRESS = gzip -9f
DISTNAME = AIRadioQt1.0.0
DISTDIR = /home/pete/Documents/AlgorythmRadio/AIRadio/build-AIRadioQt-Desktop_Qt_5_10_0_Clang_64bit-Release/.tmp/AIRadioQt1.0.0
LINK = clang++
LFLAGS = -ccc-gcc-name g++ -Wl,-rpath,/home/pete/Programming/Qt/5.10.0/gcc_64/lib
LIBS = $(SUBLIBS) -L/usr/local/lib -lcsnd6 -lcsound64 -L/home/pete/Programming/Qt/5.10.0/gcc_64/lib -lQt5DataVisualization -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
AR = ar cqs
RANLIB =
SED = sed
STRIP = strip
Now, I have looked through all the options I can think of, including the setup for each build kit, and I can't for the life of me figure out where this error is coming from.
Any idea why QMake is adding in this extra flag, and why specifically for my Clang builds? Any idea where in QtCreator I would go to change this? I have tried changing the makefiles, but obviously QMake adds the imposter flag back in when I try to build again.
EDIT:
I've tried a grep through the Qt config files as suggested by valiano below, but so far I've not turned anything up. The files containing "-std=gnu++11" are as follows:
/"path-to-qt"/mkspecs/common/qcc-base-qnx.conf
/"path-to-qt"/mkspecs/common/clang.conf
/"path-to-qt"/mkspecs/common/android-base-tail.conf
/"path-to-qt"/mkspecs/common/g++-base.conf
/"path-to-qt"/mkspecs/linux-icc/qmake.conf
/"path-to-qt"/mkspecs/macx-icc/qmake.conf
/"path-to-qt"/mkspecs/features/qt_module_headers.prf
Paths 1, 2 and 4 are the only ones that seem relevant to my situation, and none of them contain anything that looks out of the ordinary.
qcc-base-qnx.conf contains the lines:
QMAKE_CXXFLAGS_CXX11 = -Wc,-std=gnu++11
QMAKE_CXXFLAGS_CXX14 = -Wc,-std=gnu++1y
QMAKE_CXXFLAGS_CXX1Z = -Wc,-std=gnu++1z
QMAKE_LINK_C = $$QMAKE_CC
QMAKE_LINK_C_SHLIB = $$QMAKE_CC
QMAKE_LINK = $$QMAKE_CXX
QMAKE_LINK_SHLIB = $$QMAKE_CXX
this is the entire clang.conf file:
QMAKE_COMPILER = gcc clang llvm # clang pretends to be gcc
QMAKE_CC = clang
QMAKE_CXX = clang++
QMAKE_LINK_C = $$QMAKE_CC
QMAKE_LINK_C_SHLIB = $$QMAKE_CC
QMAKE_LINK = $$QMAKE_CXX
QMAKE_LINK_SHLIB = $$QMAKE_CXX
CONFIG += clang_pch_style
QMAKE_PCH_OUTPUT_EXT = .pch
QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_USE_PRECOMPILE = -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_LTCG = -flto
QMAKE_CFLAGS_DISABLE_LTCG = -fno-lto
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
QMAKE_CXXFLAGS_DISABLE_LTCG = $$QMAKE_CFLAGS_DISABLE_LTCG
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_CXX14 = -std=c++1y
QMAKE_CXXFLAGS_CXX1Z = -std=c++1z
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11
QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++1y
QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++1z
QMAKE_LFLAGS_CXX11 =
QMAKE_LFLAGS_CXX14 =
QMAKE_LFLAGS_CXX1Z =
QMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG
# Wrapper tools that understand .o/.a files with LLVM bytecode instead of machine code
QMAKE_AR_LTCG = llvm-ar cqs
QMAKE_NM_LTCG = llvm-nm -P
QMAKE_RANLIB_LTCG = true # No need to run, since llvm-ar has "s"
And this is the entire g++base.conf file:
QMAKE_COMPILER = gcc
QMAKE_CC = gcc
QMAKE_LINK_C = $$QMAKE_CC
QMAKE_LINK_C_SHLIB = $$QMAKE_CC
QMAKE_CXX = g++
QMAKE_LINK = $$QMAKE_CXX
QMAKE_LINK_SHLIB = $$QMAKE_CXX
QMAKE_PCH_OUTPUT_EXT = .gch
QMAKE_CFLAGS_PRECOMPILE = -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CFLAGS_USE_PRECOMPILE = -include ${QMAKE_PCH_OUTPUT_BASE}
QMAKE_CXXFLAGS_PRECOMPILE = -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT}
QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE
QMAKE_CXXFLAGS_CXX11 = -std=c++11
QMAKE_CXXFLAGS_CXX14 = -std=c++1y
QMAKE_CXXFLAGS_CXX1Z = -std=c++1z
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11
QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++1y
QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++1z
QMAKE_LFLAGS_CXX11 =
QMAKE_LFLAGS_CXX14 =
QMAKE_LFLAGS_CXX1Z =
I'm not much familiar with QtCreator, but you may have better luck setting C++17 using CONFIG
:
CONFIG += c++1z
If CONFIG
is set to c++11
, that could explain why the -std=gnu++11
flag is added.
Using CONFIG
should have QMake pick the correct mkspec and also set QMAKE_CXXFLAGS
with the needed -std
flag.
I just encountered the same problem, on Windows 10, when updating to QtCreator 4.9.2.
Doing this, which previously worked (for -std=c++14
and others), was no longer sufficient:
CONFIG += -std=c++17
QMAKE_CXXFLAGS += -std=c++17
-std=gnu++17
didn't work either. QMake was adding '-std=gnu++11' after all my other settings, overriding them.
The solution apparently is to add:
CONFIG += c++17
without the -std= part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With