compile c++11 file in qtcreator? problem with g++
-
wrote on 14 Jun 2016, 12:31 last edited by
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! -
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!wrote on 14 Jun 2016, 12:36 last edited by@qtpi Hi! What error does the compiler throw?
-
@qtpi Hi! What error does the compiler throw?
wrote on 14 Jun 2016, 12:49 last edited by@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 -
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!wrote on 14 Jun 2016, 13:17 last edited by@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? -
@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? -
wrote on 14 Jun 2016, 15:28 last edited by
Did you try to manually clean the project and run qmake again?
-
Did you try to manually clean the project and run qmake again?
wrote on 14 Jun 2016, 17:11 last edited by@Wieland that's a option. I will try to do it tmr.
-
wrote on 14 Jun 2016, 19:18 last edited by
@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
-
@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
wrote on 15 Jun 2016, 09:31 last edited by@medyakovvit
hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.-.- this is rly weird.
-
Did you try to manually clean the project and run qmake again?
wrote on 15 Jun 2016, 09:31 last edited by@Wieland I tried it and it still not working...-.-
-
wrote on 15 Jun 2016, 09:38 last edited by qtpi
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
hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.-.- this is rly weird.
wrote on 15 Jun 2016, 09:38 last edited by@qtpi
You tried to run this code:std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl; std::cout << __cplusplus << std::endl;
or you just look at cpluplus value from prompt?
-
@qtpi
You tried to run this code:std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl; std::cout << __cplusplus << std::endl;
or you just look at cpluplus value from prompt?
wrote on 15 Jun 2016, 09:43 last edited by@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.
7/15