• 10163阅读
  • 14回复

我是新手,写了一个HelloWorld,怎么运行出错了呢?请指教 [复制链接]

上一主题 下一主题
离线jerrycwj
 

只看楼主 正序阅读 楼主  发表于: 2006-03-21
我是新手,写了一个HelloWorld,怎么运行出错了呢?请指教
显示如下:
D:\QTest>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/qtTest'
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
ime-pseudo-reloc -Wl,-subsystem,windows -o "debug\qtTest.exe" debug\HelloWorld.o
-L"C:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
C:\Qt\4.1.1\lib/libqtmaind.a(qtmain_win.o)(.text+0x30b): In function `WinMain':
C:/Qt/4.1.1/src/winmain/qtmain_win.cpp:105: undefined reference to `qMain(int, c
har**)'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\qtTest.exe] Error 1
mingw32-make[1]: Leaving directory `D:/qtTest'
mingw32-make: *** [debug] Error 2

代码:
#include <qapplication.h>
#include <qpushbutton.h>


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

  QPushButton hello( "Hello world!", 0 );
  hello.resize( 100, 30 );

  a.setMainWidget( &hello );
  hello.show();
  return a.exec();
}
离线joetaiyuan
只看该作者 14楼 发表于: 2009-04-03
引用第12楼joetaiyuan于2009-04-03 11:23发表的  :
真是奇怪,今天我make -f makefile_release时也报了链接错误:
undefined reference to 'qMain(...)'
仅仅是一个hello工程
开发环境是刚刚布置好的
上网搜索了半天,也没有找到好的解决办法
.......


弄明白怎么回事了,是文件后缀的问题
链接有问题的情况是因为文件后缀为大写的CPP
没问题的情况,文件后缀为小写的cpp

只是弄明白了现象,不知道内部原因。
离线joetaiyuan
只看该作者 13楼 发表于: 2009-04-03
引用第12楼joetaiyuan于2009-04-03 11:23发表的  :
真是奇怪,今天我make -f makefile_release时也报了链接错误:
undefined reference to 'qMain(...)'
仅仅是一个hello工程
开发环境是刚刚布置好的
上网搜索了半天,也没有找到好的解决办法
.......


这个问题是在qt 4.4平台上出现的
同样的代码在qt 4.5平台上就没问题了,挺奇怪的
离线joetaiyuan
只看该作者 12楼 发表于: 2009-04-03
真是奇怪,今天我make -f makefile_release时也报了链接错误:
undefined reference to 'qMain(...)'
仅仅是一个hello工程
开发环境是刚刚布置好的
上网搜索了半天,也没有找到好的解决办法
看到咱们这里有提过类似的问题,想知道如何解决,多谢。
离线hau19820906
只看该作者 11楼 发表于: 2006-07-11
可能是装qt时环境变量配置错了吧
离线hau19820906
只看该作者 10楼 发表于: 2006-07-10
asdad asdasd
离线jerrycwj

只看该作者 9楼 发表于: 2006-03-22
丢脸啦
第一次接触
没办法
希望以后大家多多指教
离线jerrycwj

只看该作者 8楼 发表于: 2006-03-21
何谓通过?反正就是执行开始菜单那个指令,等它运行到出来目录提示
下午用的是公司机子,Debug库编译了半天
现在回到宿舍,库是昨晚编译的
这下更怪

D:\qtTest>qmake -project

D:\qtTest>qmake

D:\qtTest>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/qtTest'
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
-DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"C:/Qt/4.1.1/
include/QtCore" -I"C:/Qt/4.1.1/include/QtGui" -I"C:/Qt/4.1.1/include" -I"." -I"C
:/Qt/4.1.1/include/ActiveQt" -I"debug" -I"." -I"C:/Qt/4.1.1/mkspecs/win32-g++" -
o debug\HelloWorld.o HelloWorld.cpp
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
ime-pseudo-reloc -Wl,-subsystem,windows -o "debug\qtTest.exe" debug\HelloWorld.o
-L"C:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `D:/qtTest'

什么反应也没有,然后再运行

D:\qtTest>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/qtTest'
mingw32-make[1]: Nothing to be done for `first'.
mingw32-make[1]: Leaving directory `D:/qtTest'

成这样了
看过path,似乎没有问题
C:\Qt\4.1.1\bin;C:\Program Files\IDM Computer Solutions\UltraEdit-32;C:\Dev-Cpp\bin;

QTDIR 是C:\Qt\4.1.1

QMAKESPEC 是 win32-g++

焦急,敬请指教
离线XChinux

只看该作者 7楼 发表于: 2006-03-21
一、看看你的环境变量,PATH和QTDIR都设置在了哪里
二、你的Debug库已经编译通过了?怎么用的是debug的。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线jerrycwj

只看该作者 6楼 发表于: 2006-03-21
照帖子上的代码再试一次
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[]){
   QApplication app(argc, argv);
   QPushButton hello("Hello World!");
   hello.resize(100,30);
   hello.show();
   return app.exec();
}

仍然出错

F:\qtest>qmake -project

F:\qtest>qmake

F:\qtest>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `F:/qtest'
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
-DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"F:/Qt/4.1.1/
include/QtCore" -I"F:/Qt/4.1.1/include/QtGui" -I"F:/Qt/4.1.1/include" -I"." -I"F
:/Qt/4.1.1/include/ActiveQt" -I"debug" -I"." -I"F:/Qt/4.1.1/mkspecs/win32-g++" -
o debug\HelloWorld.o HelloWorld.cpp
HelloWorld.cpp:10:2: warning: no newline at end of file
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runt
ime-pseudo-reloc -Wl,-subsystem,windows -o "debug\qtest.exe" debug\HelloWorld.o
-L"F:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
debug\HelloWorld.o(.text+0x150): In function `Z5qMainiPPc':
F:/qtest/HelloWorld.cpp:5: undefined reference to `_imp___ZN12QApplicationC1ERiP
Pc'
debug\HelloWorld.o(.text+0x193):F:/qtest/HelloWorld.cpp:6: undefined reference t
o `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
debug\HelloWorld.o(.text+0x21d):F:/qtest/HelloWorld.cpp:9: undefined reference t
o `_imp___ZN12QApplication4execEv'
debug\HelloWorld.o(.text+0x23a):F:/qtest/HelloWorld.cpp:9: undefined reference t
o `QPushButton::~QPushButton()'
debug\HelloWorld.o(.text+0x24f):F:/qtest/HelloWorld.cpp:9: undefined reference t
o `QApplication::~QApplication()'
debug\HelloWorld.o(.text+0x2b2):F:/qtest/HelloWorld.cpp:9: undefined reference t
o `QPushButton::~QPushButton()'
debug\HelloWorld.o(.text+0x2df):F:/qtest/HelloWorld.cpp:9: undefined reference t
o `QApplication::~QApplication()'
debug\HelloWorld.o(.text$_ZN7QWidget6resizeEii[QWidget::resize(int, int)]+0x2d):
In function `Z18q_atomic_incrementPVi':
F:/Qt/4.1.1/include/QtCore/../../src/corelib/thread/qatomic.h: undefined referen
ce to `_imp___ZN7QWidget6resizeERK5QSize'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\qtest.exe] Error 1
mingw32-make[1]: Leaving directory `F:/qtest'
mingw32-make: *** [debug] Error 2
离线XChinux

只看该作者 5楼 发表于: 2006-03-21
那个教程是Qt4以前版本的。
Qt4的,请看Qt Programming置顶帖中的帖子和电子书。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线jerrycwj

只看该作者 4楼 发表于: 2006-03-21
我是copy教程的代码的
http://www.qiliang.net/qt/tutorial1-01.html
那请问应该去哪里找更新更好的学习资料呢?中午的最好
离线XChinux

只看该作者 3楼 发表于: 2006-03-21
把这句去掉,Qt4不用这个了
a.setMainWidget( &hello );
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线jerrycwj

只看该作者 2楼 发表于: 2006-03-21
win + Qt 4.1.1 OpenSource + devcpp-4.9.9.2
离线XChinux

只看该作者 1楼 发表于: 2006-03-21
你使用的版本几?
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个