Nominate our 2022 Qt Champions!

Mixing Objective C and C++11

  • I am unable to mix objective C and C++11 in a single Qt Project. When I try, I get the error:

    error: invalid argument '-std=c++11' not allowed with 'C/ObjC'

    I can however manually modify the Makefile to remove -std=c++11 and -stdlib=libc++ from QMAKE_COMP_QMAKE_OBJECTIVE_CFLAGS, and it works.
    Is this a bug in qmake? Should qmake not be including these values? Or I am missing something? Is there a way to setup my .pro file to create a working Makefile?

  • I use a mix of C++ and Obj-C in the Qt project without any problems.
    What I did it's just to add a source file with exentsion .mm in .pro file:

  • HA! that totally worked. Renaming .m to .mm solved it.

  • Lifetime Qt Champion


    m -> pure objective-c
    mm -> objective-c++

Log in to reply