分类:
2006-04-14 11:02:58
#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函数结束后打个回车符号