Qt: CONFIG += C++11, but -std=c++0x
Asked Answered
B

4

20

When I compile a project under Qt Creator 2.8 / Qt5.1 with VS 2010 all is fine. If I do the same with MinGW I get the following error.

 error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

I understand I need to enable C+11, but I have CONFIG += console c++11 in my .pro file. Is this not what is needed? What am I doing wrong?

When I look at the make I see:

CXXFLAGS      = -pipe -fno-keep-inline-dllexport -g -std=c++0x

Confusing, as I say c++11 in the pro file.

  1. Have deleted everything, run qmake etc, from the scratch, no result
  2. As said, with VS2010 it works
  3. Using the MinGW with gcc 4.8.0 from here. http://qt-project.org/downloads
  4. If this matters, Win7 32

Checked:

Found solution, but can only accept it in some time: https://mcmap.net/q/621243/-qt-config-c-11-but-std-c-0x

Bis answered 22/10, 2013 at 16:29 Comment(6)
It's the same thing, except -std=c++0x also works with older versions of the compiler.Bhili
Thanks. But why the "must be enabled with the -std=c++11" error when I use #include <type_traits>Bis
That is indeed weird.Bhili
Are you sure that gcc 4.8.0 is being picked up (maybe some other distro you have on the machine is being found). As @R.MartinhoFernandes says, gcc should treat -std=c++0x and -std=c++11 the same. You might try adding -v to the CXXFLAGS to get details on exactly which compiler and which include directories are being used.Reject
possible duplicate of How to enable c++11 in qt creator 2.7.0?Volkman
No, it is not a duplicate. The other question was asking about enabling C++11 in general. I did enable C++11 the correct way, but missed it in a subproject. This caused some kind of weird error and caused some kind of confusion.Bis
B
10

Ok, thanks to your hints I have figured it out.

After I have tried any possible advice from above, with still no success, I have excluded any subproject I could think of in my project. Eventually I have found a QML sample .pro which did not have CONFIG += c++11 defined.

That was causing the error. So the root cause was not the project I was working on, but a subproject which however got compiled in the same step.

Bis answered 22/10, 2013 at 23:19 Comment(0)
R
9

Try changing the mkspecs/win32-g++/qmake.conf line that says:

QMAKE_CXXFLAGS_CXX11    = -std=c++0x

to:

QMAKE_CXXFLAGS_CXX11    = -std=c++11

and re-run qmake.


Some additional details:

Adding the "c++11" feature to the CONFIG qmake variable causes the mkspecs/features/c++11.prf file to be pulled in (see the "Adding New Configuration Features" section of the qmake Advanced Usage document for details).

That qmake profile has a QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_CXX11 line among other things which configure C++11 support. So adding "c++11" to the CONFIG variable is the proper way to indicate that you want c++11 support to qmake, as you mentioned in a comment.

Reject answered 22/10, 2013 at 18:9 Comment(2)
With the latest QtCreator under Ubuntu 14.04, I still have the same issue (albeit at /usr/lib/x86_64-linux-gnu/qt5/mkspecs/common/g++-base.conf). I find it a bit alarming that I have to edit the installed conf file to get this to work. Is there a way for user config or pro/pri files to redefine this variable?Sayer
I don't know - I'm not knowledgeable enough with qmake to know if there's a user-accessible mechanism to override this.Reject
V
7

I am using Qt Creator 2.7.2, and I have this line in my .pro file:

QMAKE_CXXFLAGS += -std=c++11

Does this work for you?

Verner answered 22/10, 2013 at 16:34 Comment(1)
I will give this a trail. Somewhere I have read not to use QMAKE_CXXFLAGS but CONFIG += c++11 - but I cannot recall. Will update as soon as I have a result.Bis
F
1

qmake will use whatever flags one has for c++11. So you can overwrite them like:

unix:QMAKE_CXXFLAGS_CXX11 = -std=c++11

CONFIG *= c++11

You can even tell it to use -std=c++14 or -std=c++17 instead when c++11 is added to the config as older qmake's might not be aware of them.

Featherbrain answered 24/4, 2018 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.