• 7896阅读
  • 2回复

[讨论]Qt下的make编译老是出错 [复制链接]

上一主题 下一主题
离线hmilyylimh
 
只看楼主 倒序阅读 楼主  发表于: 2011-04-22
程序如下:#include <qapplication.h>
#include <qlabel.h>
int main(int argc,char **argv)
{
        qapplication a(argc,argv);
        qlabel *label=new qlabel("hello world!",0);
label->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
label->setGeometry(10,10,200,80);
app.setMainWidget(label);
        label->show();
int result=app.exec();
        return result;
}

我的qt安装在/tmp下,在网上搜索了一下,我还安装了g++,编译出错如下:
执行命令:progen -t app.t -o hello.pro
tmake -o makefile hello.pro后,ls一下:
hello.cpp  hello.pro  makefile
然后执行命令:make,出现的错误有:
hmily@xtu:~/文档/HELLO$ make
g++ -c -pipe -Wall -W -O2 -DNO_DEBUG -I/usr/include/qt -o hello.o hello.cpp
hello.cpp:1:26: error: qapplication.h: 没有那个文件或目录
hello.cpp:2:20: error: qlabel.h: 没有那个文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:5: error: ‘qapplication’ was not declared in this scope
hello.cpp:5: error: expected ‘;’ before ‘a’
hello.cpp:6: error: ‘qlabel’ was not declared in this scope
hello.cpp:6: error: ‘label’ was not declared in this scope
hello.cpp:6: error: expected type-specifier before ‘qlabel’
hello.cpp:6: error: expected ‘;’ before ‘qlabel’
hello.cpp:7: error: ‘Qt’ has not been declared
hello.cpp:7: error: ‘Qt’ has not been declared
hello.cpp:9: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:3: warning: unused parameter ‘argc’
hello.cpp:3: warning: unused parameter ‘argv’
make: *** [hello.o] 错误 1
而且后来我把qt里的qapplication.h,qlabel.h复制到HELLO目录下,则出现的错误为:
hmily@xtu:~/文档/HELLO$ make
g++ -c -pipe -Wall -W -O2 -DNO_DEBUG -I/usr/include/qt -o hello.o hello.cpp
hello.cpp:1:26: error: qapplication.h: 没有那个文件或目录
hello.cpp:2:20: error: qlabel.h: 没有那个文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:5: error: ‘qapplication’ was not declared in this scope
hello.cpp:5: error: expected ‘;’ before ‘a’
hello.cpp:6: error: ‘qlabel’ was not declared in this scope
hello.cpp:6: error: ‘label’ was not declared in this scope
hello.cpp:6: error: expected type-specifier before ‘qlabel’
hello.cpp:6: error: expected ‘;’ before ‘qlabel’
hello.cpp:7: error: ‘Qt’ has not been declared
hello.cpp:7: error: ‘Qt’ has not been declared
hello.cpp:9: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:3: warning: unused parameter ‘argc’
hello.cpp:3: warning: unused parameter ‘argv’
make: *** [hello.o] 错误 1
所以我很郁闷,还请各位大侠帮帮忙解决一下问题...非常感谢...
离线jyzjut
只看该作者 1楼 发表于: 2011-04-22
我也遇到了这个问题,很纠结的
离线XChinux

只看该作者 2楼 发表于: 2011-05-10
没有找到头文件,你的/usr/include/qt目录下确认有qapplication.h文件吗?
按照正常Qt开发模式来开发吧,用qmake来生成Makefile
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个