1

I've Qt 5.1.1 installed in '/Users/me/lib/qt-5.1.1/'. Under '/Users/me/lib/qt-5.1.1/5.1.1/clang_64/lib' there are all frameworks but building a simple application:

#include <QtGui>
#include <QMainWindow>
#include <qapplication.h>

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

   QMainWindow mw;
   mw.show();

   return app.exec();
}

after canonical steps:

 $qmake -project
 $qmake
 $make

linker fails to link:

Undefined symbols for architecture x86_64:
 "QMainWindow::QMainWindow(QWidget*, QFlags<Qt::WindowType>)", referenced from:
     _main in main.o
 "QMainWindow::~QMainWindow()", referenced from:
     _main in main.o
 "QApplication::exec()", referenced from:
    _main in main.o
 "QApplication::QApplication(int&, char**, int)", referenced from:
    _main in main.o
 "QApplication::~QApplication()", referenced from:
    _main in main.o
 "QWidget::show()", referenced from:
    _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test.app/Contents/MacOS/test] Error 1

I added to linker flags

-F/Users/me/lib/qt-5.1.1/5.1.1/clang_64/lib -framework QtGui -framework QtCore

clang version is:

$clang --version
Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix

Any idea?

MirkoBanchi
  • 2,173
  • 5
  • 35
  • 52

1 Answers1

1

The project generated by qmake likely doesn't include the widgets module.

Please inspect your .pro file. You do not need to add those framework linker flags manually. Simply add your modules to the QT variable:

QT += widgets

Qmake has a dependency resolution mechanism, so if you add the widgets module, the core and gui modules will be pulled in automatically.

Do note that widgets is a new module in Qt 5. In Qt 4, QWidget hierarchy was a part of the gui module. It has been separated out, creating a lightweight gui module. My other answer explains what kinds of GUI frameworks are offered in Qt 5.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Thank you, it works...i did't know about new module 'widgets'. I supposed that 'gui' and 'core' were sufficient. However i see these two modules are pulled in automatically also without specifing 'widgets' module in '.pro' file. – MirkoBanchi Oct 14 '13 at 20:16