Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1924499
  • 博文数量: 261
  • 博客积分: 8073
  • 博客等级: 中将
  • 技术积分: 2363
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-10 15:23
文章分类

全部博文(261)

文章存档

2013年(1)

2012年(1)

2011年(50)

2010年(34)

2009年(4)

2008年(17)

2007年(55)

2006年(99)

分类:

2006-04-14 11:02:58

    和老婆合作一个毕业设计嵌入式开发与设计,她做QT部分,我做内核裁减部分。今天闲来无聊,想学学QT。于是打开了QT Assistant,里面内容很丰富的说,从QT历史到QT使用,一应具全(哎,相当初要知道这个,就不会为了安装QT费那么大的劲了)。看看里面的example吧。好,先来个helloworld吧,按照文档一步一步的做:
    1、源码
      
#include
#include
int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     QPushButton hello("Hello world!");
     hello.resize(100, 30);
     hello.show();
     return app.exec();
 }
 

       保存成main.cpp

     2、打开cmd,进入main.cpp的目录,执行以下命令

        qmake -project  // 为了生成project文件

        qmake           //生成Makefile文件

        make            //生成可执行文件

        出问题了,

      

make -f Makefile.Debug
make[1]: Entering directory `C:/Qt/mypro'
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.2/
include/QtCore" -I"C:/Qt/4.1.2/include/QtGui" -I"C:/Qt/4.1.2/include" -I"." -I"C
:/Qt/4.1.2/include/ActiveQt" -I"debug" -I"." -I"C:/Qt/4.1.2/mkspecs/win32-g++" -
o debug\main.o main.cpp
main.cpp:10:4: 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\mypro.exe" debug\main.o -L"C:
\Qt\4.1.2\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
c:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot f
ind -lQtGuid4
collect2: ld returned 1 exit status
make[1]: *** [debug\mypro.exe] Error 1
make[1]: Leaving directory `C:/Qt/mypro'
make: *** [debug] Error 2

       提示mingw的ld.exe找不到QTGuid4库文件,我到QT安

        装目录的lib里查看了一下,确实没有此库,只有libQTGui4.a这

        个库文件,这个。。。。当机立断,把libQTGui4.a复制了一个,

        更改名字为libQTGuid4.a,在进行make ,不错,那个错误提示没有

        了,但是有提示找不到QTCored4库文件,

       

make -f Makefile.Debug
make[1]: Entering directory `C:/Qt/mypro'
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.2/
include/QtCore" -I"C:/Qt/4.1.2/include/QtGui" -I"C:/Qt/4.1.2/include" -I"." -I"C
:/Qt/4.1.2/include/ActiveQt" -I"debug" -I"." -I"C:/Qt/4.1.2/mkspecs/win32-g++" -
o debug\main.o main.cpp
main.cpp:10:4: 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\mypro.exe" debug\main.o -L"C:
\Qt\4.1.2\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
c:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot f
ind -lQtGuid4
collect2: ld returned 1 exit status
make[1]: *** [debug\mypro.exe] Error 1
make[1]: Leaving directory `C:/Qt/mypro'
make: *** [debug] Error 2

        照葫芦画瓢,再复制一份

        libQTCored4.a,在运行make ,顺利通过。

        虽然错误解决了,但是不知道是为什么,按说应该在安装QT时产生

        那两个库文件的,可是。。。。反正是奇怪,继续寻找答案

PS:注意这个警告

main.cpp:10:4: warning: no newline at end of file

错误原由: Each instance of a backslash character (\) immediately followed by a
new-line character is deleted, splicing physical source lines to form logical
source lines. Only the last backslash on any physical source line shall be
eligible for being part of such a splice. A source file that is not empty
shall end in a new-line character, which shall not be immediately preceded
by a backslash character before any such splicing takes place.

改正方法:在main函数结束后打个回车符号

      

阅读(6623) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~