您的位置:首页 > 移动开发

QT编译出现fatal error: QApplication: No such file or directory

2013-10-13 21:29 525 查看
#include <QApplication>

#include <QLabel>

int main(int argc, char **argv)

{

QApplication app(argc, argv);

QLabel *label = new QLabel("hello world");

label->show();

return app.exec();

}

yijun@ubuntu:~/qt/hello$ qmake -project

yijun@ubuntu:~/qt/hello$ qmake hello.pro

运行出错

yijun@ubuntu:~/qt/hello$ make

g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../../Qt5.1.1/5.1.1/gcc/mkspecs/linux-g++ -I. -I. -I../../Qt5.1.1/5.1.1/gcc/include -I../../Qt5.1.1/5.1.1/gcc/include/QtGui -I../../Qt5.1.1/5.1.1/gcc/include/QtCore -I.
-o main.o main.cpp

main.cpp:1:24: fatal error: QApplication: No such file or directory

compilation terminated.

yijun@ubuntu:~/qt/hello$

因为Qt5里不再用QtGui模块,而是使用QtWidgets模块,

所以在.pro里加上

在hello.pro文件中添加

QT += core gui widgets

yijun@ubuntu:~/qt/hello$ make

/home/yijun/Qt5.1.1/5.1.1/gcc/bin/qmake -o Makefile hello.pro

g++ -Wl,-O1 -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc/lib -o hello main.o -L/home/yijun/Qt5.1.1/5.1.1/gcc/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread

/usr/bin/ld: cannot find -lGL

collect2: ld returned 1 exit status

make: *** [hello] Error 1

yijun@ubuntu:~/qt/hello$

解决办法:

sudo apt-get install libglu1-mesa-dev -y

装完以后(装的过程比较漫长,而且网速也不给力,装完就重启了ubuntu)

yijun@ubuntu:~/qt/hello$ make

g++ -Wl,-O1 -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc -Wl,-rpath,/home/yijun/Qt5.1.1/5.1.1/gcc/lib -o hello main.o -L/home/yijun/Qt5.1.1/5.1.1/gcc/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread

yijun@ubuntu:~/qt/hello$

成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐