PDA

View Full Version : hello.qt make erro!



soliveira
5th February 2010, 12:28
hi all
Error my make!

am new to QT


my code

#include <qapplication.h>
#include <qlabel.h>

int main (int argc, char*argv[])
{
QApplication app(argc, argv);
QLabel * label = new QLabel ("Hello QT!", 0);
app.setMainWidget (label);
label->show();
return app.exec();
}



all Error

root@nin-aesa:~/qt# make
g++ -o qt hello.o -L/usr/X11R6/lib -lXext -lX11 -lm -lpthread
hello.o: In function `main':
/home/soliveira/qt/hello.cpp:6: undefined reference to `QApplication::QApplication(int&, char**)'
/home/soliveira/qt/hello.cpp:7: undefined reference to `QString::QString(char const*)'
/home/soliveira/qt/hello.cpp:7: undefined reference to `QLabel::QLabel(QString const&, QWidget*, char const*, unsigned int)'
hello.o: In function `~QString':
/usr/include/qt3/qstring.h:850: undefined reference to `QString::shared_null'
/usr/include/qt3/qstring.h:851: undefined reference to `QStringData::deleteSelf()'
hello.o: In function `main':
/home/soliveira/qt/hello.cpp:8: undefined reference to `QApplication::setMainWidget(QWidget*)'
/home/soliveira/qt/hello.cpp:10: undefined reference to `QApplication::exec()'
/home/soliveira/qt/hello.cpp:10: undefined reference to `QApplication::~QApplication()'
hello.o: In function `~QString':
/usr/include/qt3/qstring.h:850: undefined reference to `QString::shared_null'
/usr/include/qt3/qstring.h:851: undefined reference to `QStringData::deleteSelf()'
hello.o: In function `main':
/home/soliveira/qt/hello.cpp:10: undefined reference to `QApplication::~QApplication()'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0xc): undefined reference to `QGList::clear()'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x10): undefined reference to `QGList::~QGList()'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x14): undefined reference to `QGList::~QGList()'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x18): undefined reference to `QPtrCollection::newItem(void*)'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x20): undefined reference to `QGList::compareItems(void*, void*)'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
hello.o:(.rodata._ZTV6QGList[vtable for QGList]+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
hello.o:(.rodata._ZTI6QGList[typeinfo for QGList]+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: ** [qt] Erro 1

Tank all!!

squidge
5th February 2010, 13:40
Try including QtCore and QtGUI in your library list

graciano
6th February 2010, 09:58
Your code:


#include <QApplication>
#include <QLabel>

int main (int argc, char*argv[])
{
QApplication app(argc, argv);
QLabel * label = new QLabel ("Hello QT!", 0);
//app.setMainWidget (label);
label->show();
return app.exec();
}

bender86
6th February 2010, 10:57
You are not linking with Qt libraries.
Have you created a .pro file an run "qmake" before running make?

oldjack
11th February 2010, 00:16
Hi,

I'm having a similar problem. Being new to Qt, I've spent several hours trying to research and fix this but haven't been able to. Using both the Eclipse plug-in and the Qt Command Prompt, I get the same error, even on a new project with no code in it.

mingw32-make debug
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Eclipse/workspace/QtTest'
c:\Qt\2009.05\qt\bin\uic.exe qttest.ui -o ui_qttest.h
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2009.05\qt\include\QtCore" -I"c:\Qt\2009.05\qt\include\QtGui" -I"c:\Qt\2009.05\qt\include" -I"c:\Qt\2009.05\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2009.05\qt\mkspecs\default" -o debug\main.o main.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2009.05\qt\include\QtCore" -I"c:\Qt\2009.05\qt\include\QtGui" -I"c:\Qt\2009.05\qt\include" -I"c:\Qt\2009.05\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2009.05\qt\mkspecs\default" -o debug\qttest.o qttest.cpp
C:/Qt/2009.05/qt/bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2009.05\qt\include\QtCore" -I"c:\Qt\2009.05\qt\include\QtGui" -I"c:\Qt\2009.05\qt\include" -I"c:\Qt\2009.05\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2009.05\qt\mkspecs\default" -D__GNUC__ -DWIN32 qttest.h -o debug\moc_qttest.cpp
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2009.05\qt\include\QtCore" -I"c:\Qt\2009.05\qt\include\QtGui" -I"c:\Qt\2009.05\qt\include" -I"c:\Qt\2009.05\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2009.05\qt\mkspecs\default" -o debug\moc_qttest.o debug\moc_qttest.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\QtTest.exe debug/main.o debug/qttest.o debug/moc_qttest.o -L"c:\Qt\2009.05\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
c:\Qt\2009.05\qt\lib/libqtmaind.a(qtmain_win.o): In function `WinMain@16':
C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:93: undefined reference to `_Unwind_Resume'
C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:135: undefined reference to `_Unwind_Resume'
c:\Qt\2009.05\qt\lib/libqtmaind.a(qtmain_win.o):C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/../../include/QtCore/../../src/corelib/tools/qvector.h:481: undefined reference to `_Unwind_Resume'
mingw32-make[1]: Leaving directory `C:/Eclipse/workspace/QtTest'
c:\Qt\2009.05\qt\lib/libqtmaind.a(qtmain_win.o):C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/../../include/QtCore/../../src/corelib/tools/qvector.h:482: undefined reference to `_Unwind_Resume'
c:\Qt\2009.05\qt\lib/libqtmaind.a(qtmain_win.o):qtmain_win.cpp:(.eh_fra me+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtTest.exe] Error 1
mingw32-make: *** [debug] Error 2

I understand that I need to link with a Qt library here, and believe I should be able to edit the .pro file to correct this, but don't see how to do it. In searching the online docs about .pro files, I didn't see any detail on editing them. Here's my current project file, note that it appears to me to already include QtCore and QtGui:

TEMPLATE = app
TARGET = QtTest

QT += core gui

HEADERS += qttest.h
SOURCES += main.cpp \
qttest.cpp
FORMS += qttest.ui
RESOURCES +=

I'm running Windows Vista, Qt SDK 2009.05 (Qt 4.6.0) and Eclipse Integration 1.6.0. I get a similar error on various projects in Qt Creator 1.3.0.

I'm hoping to make a change from Visual Studio to Qt (with or without Eclipse); at my office there's a push to convert to Java, but I would like to give Qt a go. Thanks for your help.

oldjack

oldjack
11th February 2010, 01:48
I've found this part of the documentation which details working with qmake Project files (.pro):

http://qt.nokia.com/doc/4.6/qmake-project-files.html

However, from what I understand so far, it seems my project file is fine and the line

QT += core gui

includes the correct libraries. So I'm completely uncertain as to what the problem might be.

oldjack