终端下用指令编译通过,使用KDevelop编译失败的原因在那里?
源程序如下:
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <QtCore/QTextCodec>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
QWidget *pWidget = new QWidget;
QLabel label(pWidget);
label.resize(200, 60);
label.setText(QObject::tr("同一个世界,同一个梦想!"));
pWidget->show();
return app.exec();
}
编译出错信息:
cd '/media/MEDIA/program/QT/hello' && LC_MESSAGES="C" LC_CTYPE="C" make clean && LC_MESSAGES="C" LC_CTYPE="C" make
cd src/ && make -f Makefile clean
rm -f main.o
rm -f *~ core *.core
cd src/ && make -f Makefile
正在编译 main.cpp (g++)
正在连接 ../bin/hello (g++)
main.o: In function `main':
main.cpp:(.text+0x31): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cpp:(.text+0x95): undefined reference to `QWidget::QWidget(QWidget*, QFlags<Qt::WindowType>)'
main.cpp:(.text+0xb2): undefined reference to `QLabel::QLabel(QWidget*, QFlags<Qt::WindowType>)'
main.cpp:(.text+0xcf): undefined reference to `QWidget::resize(QSize const&)'
main.cpp:(.text+0x101): undefined reference to `QLabel::setText(QString const&)'
main.cpp:(.text+0x12e): undefined reference to `QApplication::exec()'
main.cpp:(.text+0x138): undefined reference to `QLabel::~QLabel()'
main.cpp:(.text+0x143): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0x15e): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0x18a): undefined reference to `QLabel::~QLabel()'
collect2: ld returned 1 exit status
make[1]: *** [../bin/hello] Error 1
make: *** [sub-src-make_default] Error 2
*** 退出状态:2 ***
网上有人说可能是因为头文件找不到导致,如果是这样的话,我猜测问题应该是IDE引起的,那么该如何解决呢?是设置项目参数的时候出错了吗?
另外,用KDevelop编译如下代码的时候没有问题。
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qDebug("Hello from Qt 4!");
return 0;
}
原因何在?大家帮忙分析解决一下。谢谢!