Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. compile c++11 file in qtcreator? problem with g++
QtWS25 Last Chance

compile c++11 file in qtcreator? problem with g++

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 6.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtpi
    wrote on last edited by
    #1

    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!

    ? miclandM 2 Replies Last reply
    0
    • Q qtpi

      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!

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @qtpi Hi! What error does the compiler throw?

      Q 1 Reply Last reply
      0
      • ? A Former User

        @qtpi Hi! What error does the compiler throw?

        Q Offline
        Q Offline
        qtpi
        wrote on last edited by
        #3

        @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?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hi
          can you try with
          QMAKE_CXXFLAGS += -std=c++11

          Q 1 Reply Last reply
          0
          • Q qtpi

            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!

            miclandM Offline
            miclandM Offline
            micland
            wrote on last edited by
            #5

            @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?

            Q 1 Reply Last reply
            1
            • mrjjM mrjj

              hi
              can you try with
              QMAKE_CXXFLAGS += -std=c++11

              Q Offline
              Q Offline
              qtpi
              wrote on last edited by
              #6

              @mrjj

              hi. actually both configurations are in my .pro file. still shows it's c++98 mode. -.-

              1 Reply Last reply
              0
              • miclandM micland

                @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?

                Q Offline
                Q Offline
                qtpi
                wrote on last edited by
                #7

                @micland thanks for the help. actually I tried these 2 different cases already. seems still not working.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Did you try to manually clean the project and run qmake again?

                  Q 2 Replies Last reply
                  0
                  • ? A Former User

                    Did you try to manually clean the project and run qmake again?

                    Q Offline
                    Q Offline
                    qtpi
                    wrote on last edited by
                    #9

                    @Wieland that's a option. I will try to do it tmr.

                    M 1 Reply Last reply
                    0
                    • Q qtpi

                      @Wieland that's a option. I will try to do it tmr.

                      M Offline
                      M Offline
                      medyakovvit
                      wrote on last edited by
                      #10

                      @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

                      Q 1 Reply Last reply
                      2
                      • M medyakovvit

                        @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

                        Q Offline
                        Q Offline
                        qtpi
                        wrote on last edited by
                        #11

                        @medyakovvit
                        hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.

                        -.- this is rly weird.

                        M 1 Reply Last reply
                        0
                        • ? A Former User

                          Did you try to manually clean the project and run qmake again?

                          Q Offline
                          Q Offline
                          qtpi
                          wrote on last edited by
                          #12

                          @Wieland I tried it and it still not working...-.-

                          1 Reply Last reply
                          0
                          • Q Offline
                            Q Offline
                            qtpi
                            wrote on last edited by qtpi
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • Q qtpi

                              @medyakovvit
                              hi. thanks for the help. the gcc is 4.9 and the macro __cplusplus shows 199711.

                              -.- this is rly weird.

                              M Offline
                              M Offline
                              medyakovvit
                              wrote on last edited by
                              #14

                              @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?

                              Q 1 Reply Last reply
                              0
                              • M medyakovvit

                                @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?

                                Q Offline
                                Q Offline
                                qtpi
                                wrote on last edited by
                                #15

                                @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.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved