Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error building simple Qt5 application

I installed Qt 5.0.0 (qt-mac-opensource-5.0.0-clang-offline.dmg) on a Mac OS X 10.7.5 and now I'm trying to compile a "Hello World" application using Qt Creator 2.6.1.

The build process complains about a directory not found: /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib , followed by several linking errors:

clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/mkspecs/macx-clang -I. -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtGui -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtCore -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o main.o main.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o hello_qt.app/Contents/MacOS/hello_qt main.o -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib -framework QtGui -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib -framework QtCore -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib'
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main.o
"QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)", referenced from:
_main in main.o
"QWidget::show()", referenced from:
_main in main.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in main.o
"QApplication::exec()", referenced from:
_main in main.o
"QPushButton::~QPushButton()", referenced from:
_main in main.o
"QLabel::~QLabel()", referenced from:
_main in main.o
"QApplication::~QApplication()", 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: *** [hello_qt.app/Contents/MacOS/hello_qt] Error 1

It's important to note that the path /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib is not valid because the directory qtbase doesn't exist. The working path is /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib. I'm not referring to qtbase anywhere in my project, so this is probably being added by qmake.

like image 654
karlphillip Avatar asked Jan 23 '13 12:01

karlphillip


1 Answers

As it turns out, the invalid qtbase path thing is really a Qt bug originally reported at QTBUG-28336.

The linking problem is due to my project not linking with QtWidgets, which is something we are going to have to do starting in Qt5. This is accomplished by adding the following line to your .pro file:

QT += widgets
like image 196
karlphillip Avatar answered Oct 15 '22 10:10

karlphillip