Important: Please read the Qt Code of Conduct -

Qt Creator and GCC 4.6 on Mac

  • Hi to all!

    As Apple is now concentrating on LLVM/Clang and i don't know if will ever update it's tools with a newer GCC version, i installed it myself using macports. So, i have a valid GCC 4.6 installation on /opt/local/bin.
    I added it to Qt Creator (through Build and Run/Toolchains menu), selected it as project tool chain and it seems to compile things just fine. Unless, i use some C++ 11 feature that is indeed supported by this version of GCC, like the "auto" keyword.

    By using the command line of g++-mp-4.6, a project with C++ 11 features compile juts fine, if of course, i add the "-std=c++11" switch to the compiler.

    It seems that i cannot make Qt Creator (latest version on Qt 4.8.0) "understand" it and compile correctly. I have put that "QMAKE_CXXFLAGS += -std=c++11" (or QMAKE_CXXFLAGS += -std=c++0x) in the .pro file and then i get:

    "error: [main.o] Error 1"

    when compiling.

    I also tried to pass it as a Qmake argument with no luck.

    What am i doing wrong with this ?

    Thanks a lot for any help.

  • Moderators

    Do you have the full output? The line you gave just points to the linker but does not provide any useful information what it might be complaining about.

  • Thanks for the reply!

    My mac is at home and when i get back (at the afternoon) i will post back all the output needed.

  • Ok, the Compiler Output is this:

    22:36:22: Running build steps for project eSTL1...
    22:36:22: Configuration unchanged, skipping qmake step.
    22:36:23: Starting: "/usr/bin/make" -w
    make: Entering directory /Users/objectref/Projects/tests/C++/eSTL1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug' g++ -c -pipe -std=c++0x -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -I../../../../QtSDK/Desktop/Qt/4.8.0/gcc/mkspecs/macx-g++ -I../eSTL1 -I../eSTL1 -I. -o main.o ../eSTL1/main.cpp cc1plus: error: unrecognized command line option "-std=c++0x" make: *** [main.o] Error 1 make: Leaving directory/Users/objectref/Projects/tests/C++/eSTL1-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug'
    22:36:23: The process "/usr/bin/make" exited with code 2.
    Error while building project eSTL1 (target: Desktop)
    When executing build step 'Make'

    I understand that["cc1plus: error: unrecognized command line option "-std=c++0x"] is the error but the same command option is working fine under command line.

    I am sure i am missing something obvious here...

  • Moderators

    It might be using the wrong g++ then. Can you please check the PATH in Projects->Build Settings, Build Environment?

  • says: "/opt/local/bin:/Users/objectref/QtSDK/Desktop/Qt/4.8.0/gcc/bin:/usr/bin:/bin:/usr/sbin:/sbin"

    EDIT: I instructed to run g++-mp-4.6, not g++ (through the Toolchain addition that i made) but qmake "effective call" goes like this: "qmake /Users/objectref/Projects/tests/C++/eSTL1/ -r -spec macx-g++ CONFIG+=declarative_debug"

  • You should at least use QMAKE_CXXFLAGS += ...

    Just "=" overwrites anything that was already there.

  • Hi,

    i am indeed use it in .pro file as you say. (It was just a typo in my above post.)

    So, my .pro file is:

    QMAKE_CXXFLAGS += -std=c++0x
    TEMPLATE = app
    CONFIG += console
    CONFIG -= qt
    SOURCES += main.cpp

    Any ideas of what is going on ?

    EDIT: i use the "+" before the "=" but when i post to the forum i only get the "=" (an the rest) underlined!!

  • In /opt/local/bin there is g++ (gcc 4.2) as well as g++-mp-4.6 (gcc 4.6). It seems to insist calling g++ and not g++-mp-4.6 even though in toolchain i specifically selected the second one...

  • Hi again!

    Does anyone find a solution to this ?

    Thanks for any help!

  • Moderators

    Yeap, qmake will call whatever the mkspec tells it to, there is little we can do to override that from Qt Creator:-(

    You can either install the different gccs into separate directories to work around the issue or add a new mkspec that uses the correct compiler to your Qt and ask creator to use that one. You can then override the mkspec used in your project or (with a creator from master) override the mkspec in the tool chain.

  • Ok Tobias, thanks for the help!

    I will follow your instructions. Still, i was expecting something less complicated...

  • You can try MacPorts select command to make gcc46 the default gcc from opt/:
    $ sudo port select gcc mp-gcc46@

    Creator will than be able to pass -std=c++0x to the correct compiler. Note that -arch option is not available in non-Apple gcc. With Creator 2.5 RC, it insists on adding CONFIG+=x86_64 to qmake step, which in turn causes gcc to error on -arch option.

  • I'm stuck just getting started with the example using creator on the Mac.

    #include <QApplication>
    #include <QDialog>

    #include "ui_gotocelldialog.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    Ui::GoToCellDialog ui;
    QDialog dialog = new QDialog;
    ui.setupUi( dialog ); //compile error here: no matching function for call to 'UI::GoToCellDialog::setupUi(QDialog
    // ui.setupUi( (QMainWindow*)dialog ); //Mac compiler needs the typecast to QMainWindow
    // to compile but encountered EXC_BAD_ACCESS on runtime

    return app.exec();

    from ui_gotocelldialog.h

    void setupUi(QMainWindow *GoToCellDialog)

    Any thoughts are much appreciated!

Log in to reply