compile c++11 file in qtcreator? problem with g++
-
hey folks. the problem is as described in title. I added the CONFIG += C++11 in the .pro file. and it still cannot compile the file with c++11.
I am not sure if there is problem with gcc cause when I checked the qmake command in the project option, it shows: qmake xxx.pro -r -spec linux-g++
and my gcc is 4.9.2 so I think it is new enough to recognize c++11.
my qt version is 5.3.2.what could be the problem?
Thanks in advance! -
@Wieland hey. it says range-based 'for' loops are not allowed in c++98 mode.
I am very confused. how come is it c++98?
-
hi
can you try with
QMAKE_CXXFLAGS += -std=c++11 -
@qtpi said:
hey folks. the problem is as described in title. I added the CONFIG += C++11 in the .pro file. and it still cannot compile the file with c++11.
I'm not sure if the config values are case sensitive but I always used
CONFIG += c++11
(with a lower cased C) which worked for me... give it a try? -
Did you try to manually clean the project and run qmake again?
-
@Wieland that's a option. I will try to do it tmr.
-
@qtpi
Another places to check:
Check that you use correct gcc. There are a few versions of gcc can be installed. For example, i have gcc-4.8, gcc-4.9 and gcc-5. You can choose version to use with simple "gcc"(without mentioning any version) through
update-alternatives.Another option, if you use Qt Creator you can manually compiler in Options->Build&Run in Compilers tab. In Compiler path you can point to concrete version, for example /usr/bin/g++-5.
Also, you can check compiler version and c++ standart at runtime, with:
std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl; std::cout << __cplusplus << std::endl;
Here you can find values returned by __cplusplus macro
-
@medyakovvit
hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.-.- this is rly weird.
-
@Wieland I tried it and it still not working...-.-
-
update: I just solved the problem. I have included my source .pro as a sub .pro file in another .pro file: mySoftware.pro and I only changed the setting in mySoftware.pro.
After I changed the setting in the source.pro, everything works.
-
@medyakovvit said:
I dont have the macro GNUC_PATCHLEVEL . So i only tried to check GNU MINOR and cplusplus.
but the problem is solved, it seems if the pro file is placed on each other. it might be sometimes problematic with this setting.