Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Can I use clang with -std=c++17 in qmake?

Can I use clang with -std=c++17 in qmake?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
10 Posts 3 Posters 23.6k 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.
  • E Offline
    E Offline
    equituk
    wrote on 17 Oct 2017, 18:25 last edited by
    #1

    I'd like to compile a project using c++17. The project uses qmake from 5.9.2 as its build system and clang 5 as the compiler. Clang 5 supports the -std=c++17 switch to compile in c++17 mode.

    At the moment we can't just add "c++17" to CONFIG in the .pro file (because that's not currently a recognised option for CONFIG), so I've done this:

    CONFIG += c++14 qt dll debug_and_release
    
    equals(QMAKE_CXX, clang++) {
        message("enabling c++17 support in clang")
        QMAKE_CXXFLAGS += -std=c++17
    }
    

    Which adds the appropriate -std=c++17 switch to the clang++ command, but unfortunately the compiler command line this generates is:

    clang++ -c -pipe -std=c++17 -g -std=gnu++1y [...]
    

    which means the -std=gnu++1y overrides the -std=c++17 and the compiler works in c++14 mode.
    I've also tried this slight modification:

    CONFIG += c++14 qt dll debug_and_release
    
    equals(QMAKE_CXX, clang++) {
        message("enabling c++17 support in clang")
        QMAKE_CXXFLAGS += -std=c++17
        CONFIG -= c++14
    }
    

    which makes the compiler command:

    clang++ -c -pipe -std=c++17 -g -std=gnu++11 [...]
    

    so it compiles in c++11 mode, which is worse!

    Is there any way to force qmake to ask the compiler to work in c++17 mode? Is there any way to get options into the compiler command-line after those placed there by what's in CONFIG? Or to stop CONFIG from placing any language-standard option in the compiler command-line? I've searched and read but I can't find anything. Is it just not possible to coerce qmake into issuing compiler command lines that work in c++17 mode?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Oct 2017, 19:15 last edited by
      #2

      Hi and welcome to devnet,

      Please try CONFIG += c++1z

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 21 Feb 2018, 09:48
      4
      • E Offline
        E Offline
        equituk
        wrote on 18 Oct 2017, 17:07 last edited by
        #3

        That definitely puts the compiler in c++17 (or c++1z) mode, thanks. I didn't know about that option for CONFIG and it doesn't seem to be documented anywhere that google can find. Good to know.

        Sadly it's not solved my overall problem (class template argument type deduction), but now it's probably my code's fault :(

        Anyway, you've answered the question I asked, so many thanks for that.

        1 Reply Last reply
        0
        • S SGaist
          17 Oct 2017, 19:15

          Hi and welcome to devnet,

          Please try CONFIG += c++1z

          P Offline
          P Offline
          pawel.skorupinski_ne
          wrote on 21 Feb 2018, 09:48 last edited by
          #4

          @SGaist I have added CONFIG += c++1z line in the .pro file and on build (after clean and qmake) I am still getting this error:
          error: C1189: #error: class template optional is only available with C++17.
          This is for MSVC. MinGW simply says "no such file or directory" referring to the same class.

          We are using Qt 5.9.2.

          Any ideas? Thank you so much!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 21 Feb 2018, 10:53 last edited by
            #5

            What version of MSVC ? Note that MSVC doesn't care about that flag because it always builds code with the feature set of the C++ standard it implements.
            What version of MinGW ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            P 1 Reply Last reply 21 Feb 2018, 14:47
            0
            • S SGaist
              21 Feb 2018, 10:53

              What version of MSVC ? Note that MSVC doesn't care about that flag because it always builds code with the feature set of the C++ standard it implements.
              What version of MinGW ?

              P Offline
              P Offline
              pawel.skorupinski_ne
              wrote on 21 Feb 2018, 14:47 last edited by
              #6

              @SGaist I am trying with MinGW 5.3.0 32bit and MSVC 2017 (Compiler 15.0)

              P 1 Reply Last reply 21 Feb 2018, 16:44
              0
              • P pawel.skorupinski_ne
                21 Feb 2018, 14:47

                @SGaist I am trying with MinGW 5.3.0 32bit and MSVC 2017 (Compiler 15.0)

                P Offline
                P Offline
                pawel.skorupinski_ne
                wrote on 21 Feb 2018, 16:44 last edited by pawel.skorupinski_ne
                #7

                As explained here, since 15.3, Visual Studio compiler expects flag /std:c++17. I have Visual Studio Build Tools 2017 v15.5.7 installed (although Qt still says it is compiler 15.0).

                Is there any chance to have qmake pass the flag above to cl.exe? In Compile Output, there is no sign of this flag (we have seen it with MinGW though when CONFIG += c++1z was used).

                Thank you!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 21 Feb 2018, 20:22 last edited by SGaist
                  #8

                  Thanks for the link !

                  After a quick check, it looks like it's not in yet. You can use QMAKE_CXXFLAG and pass the flag manually for the moment.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  P 1 Reply Last reply 23 Feb 2018, 19:57
                  0
                  • S SGaist
                    21 Feb 2018, 20:22

                    Thanks for the link !

                    After a quick check, it looks like it's not in yet. You can use QMAKE_CXXFLAG and pass the flag manually for the moment.

                    P Offline
                    P Offline
                    pawel.skorupinski_ne
                    wrote on 23 Feb 2018, 19:57 last edited by
                    #9

                    @SGaist It did not work with the flag specification either...
                    I have posted the detailed explanation of issues with both compilers in two Stack Overflow posts.
                    https://stackoverflow.com/questions/48953986/build-qt-project-with-vs-c-compiler-15-0-with-c17-to-use-winrt-apis
                    https://stackoverflow.com/questions/48955243/build-qt-project-with-mingw-to-use-winrt-apis

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 23 Feb 2018, 20:17 last edited by
                      #10

                      WinRT ? You should have mentioned that earlier. Why don't use one of Qt's WinRT builds ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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