Qt Creator and GCC 4.6 on Mac
-
wrote on 20 Feb 2012, 20:20 last edited by
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.
-
wrote on 21 Feb 2012, 07:42 last edited by
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.
-
wrote on 21 Feb 2012, 08:40 last edited by
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.
-
wrote on 21 Feb 2012, 20:40 last edited by
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...
-
wrote on 21 Feb 2012, 21:51 last edited by
It might be using the wrong g++ then. Can you please check the PATH in Projects->Build Settings, Build Environment?
-
wrote on 21 Feb 2012, 22:00 last edited by
Xmmm...it 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/eSTL1.pro -r -spec macx-g++ CONFIG+=declarative_debug"
-
wrote on 22 Feb 2012, 00:37 last edited by
You should at least use QMAKE_CXXFLAGS += ...
Just "=" overwrites anything that was already there.
-
wrote on 22 Feb 2012, 18:12 last edited by
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.cppAny 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!!
-
wrote on 23 Feb 2012, 08:51 last edited by
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...
-
wrote on 2 Mar 2012, 17:20 last edited by
Hi again!
Does anyone find a solution to this ?
Thanks for any help!
-
wrote on 6 Mar 2012, 10:09 last edited by
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.
-
wrote on 10 Mar 2012, 15:27 last edited by
Ok Tobias, thanks for the help!
I will follow your instructions. Still, i was expecting something less complicated...
-
wrote on 2 May 2012, 21:54 last edited by
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.
-
wrote on 11 Dec 2012, 02:01 last edited by
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
dialog->show();return app.exec();
}from ui_gotocelldialog.h
void setupUi(QMainWindow *GoToCellDialog)
Any thoughts are much appreciated!