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



  • 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!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Please try CONFIG += c++1z



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.