Adding extra compiler option in Qt

72,488

Solution 1

You can try adding

QMAKE_CXXFLAGS += -std=c++0x

to your .pro file.

However, this should not be used in Qt 5 for enabling specific c++ standard. Instead, c++11 or c++14 in CONFIG variable to do that. It will enable GNU extensions (-std=gnu++11), but if that is unwanted, also add strict_c++ if you want to disable those. For example, this should pass -std=c++11 to the compiler:

CONFIG += c++11 strict_c++

Solution 2

In your .pro file, you could add:

QMAKE_CXXFLAGS += -std=c++0x

I think every variable in the spec's qmake.conf can be altered like that.

For example, the win32-g++ spec has, among other variables, these:

QMAKE_CC        = gcc
QMAKE_LEX       = flex
QMAKE_LEXFLAGS      =
QMAKE_YACC      = byacc
QMAKE_YACCFLAGS     = -d
QMAKE_CFLAGS        =
QMAKE_CFLAGS_DEPS   = -M
QMAKE_CFLAGS_WARN_ON    = -Wall
QMAKE_CFLAGS_WARN_OFF   = -w
QMAKE_CFLAGS_RELEASE    = -O2
QMAKE_CFLAGS_DEBUG  = -g
QMAKE_CFLAGS_YACC   = -Wno-unused -Wno-parentheses

QMAKE_CXX       = g++
QMAKE_CXXFLAGS      = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE  = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG    = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD   = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_RTTI_ON  = -frtti
QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions

Solution 3

The way QT deals with compiler options is through the .pro file. It is a double edged sword if I may. It creates a nice abstraction, especially when compiling large projects. The problem is that you have to either look up or memorize how to add the flag. In the case of C++0X, you have to add the following flag to your .pro file:

QMAKE_CXXFLAGS += -std=c++0x

Fortunately most of the flags that you need are automatically added if you use QtCreator.

Share:
72,488

Related videos on Youtube

smallB
Author by

smallB

Updated on July 09, 2022

Comments

  • smallB
    smallB almost 2 years

    Where in Qt can I specify additional compiler options? Like for example -std=c++0x?

    • Jay
      Jay almost 13 years
      in Qt designer? Netbeans? What are you using as an IDE?
    • Fred Foo
      Fred Foo almost 13 years
      Do you mean in a qmake file?
    • Violet Giraffe
      Violet Giraffe almost 13 years
      I don't know what exactly TS meant, but I'd like to know to know how to specify compiler options in a .pro file.
    • smallB
      smallB almost 13 years
      @all sorry I didn't mention, I'm using QtDesigner
  • mchiasson
    mchiasson over 9 years
    This specific flag is also done for you if you do CONFIG += c++11
  • SR_
    SR_ over 6 years
    Even if it is obvious, the documentation is here : doc.qt.io/qt-5/qmake-variable-reference.html