Windows下使用MakeFile(Mingw)文件
下面是我基于《C++GUI QT4编程(第二版)》 2.3节快速设计对话框编写例子地址:
https://files.cnblogs.com/files/senior-engineer/gotocell.7z
缘由:本人想在windows下创建Qt工程并编译,安装qt-opensource-windows-x86-mingw530-5.7.0.exe包,使用集成开发环境IDE编译无问题,但是本人想试一下make本地编译生成xxx.exe结果遇到些问题,在此分享
根据QT4.0书上说明构建步骤如下:(以helloQt项目名为例)
1.在命令提示符下,进入hello目录,输入如下命令,生成一个与平台无关hello.pro:
qmake -project
2.然后,键入如下命令,从这个项目生成一个与平台相关的makefile文件:
qmake helloQt.pro
3.键入make命令就可以构建改程序。
遇到问题:
1.首相windows下没有qmake命令,但是安装完qt-opensource-windows-x86-mingw530-5.7.0.exe包之后,安装目录下就有一个qmake.exe文件,可使用everything工具全盘搜索,即可见到,
现在我们有两种方案,1,在qmake.exe文件夹目录下运行qmake指令(仅限此目录下可以识别qmake);2.添加环境变量到path下,就可以任何目录下运行qmake。
执行完qmake -project命令生成平台无关文件helloQt.pro内容如下:

######################################################################
# Automatically generated by qmake (3.0) ?? ?? 16 19:35:06 2016
###################################################################### TEMPLATE = app
TARGET = helloQt
INCLUDEPATH += . # Input
HEADERS += mainwindow.h ui_mainwindow.h
FORMS += mainwindow.ui
SOURCES += main.cpp mainwindow.cpp

2.执行完qmake helloQt.pro命令生成平台相关的makefile文件

#############################################################################
# Makefile for building: helloQt
# Generated by qmake (3.0) (Qt 5.7.0)
# Project: helloQt.pro
# Template: app
# Command: D:\ProgramFilies\Qt5.7.0\5.7\mingw53_32\bin\qmake.exe -o Makefile helloQt.pro
############################################################################# MAKEFILE = Makefile first: release
install: release-install
uninstall: release-uninstall
QMAKE = D:\ProgramFilies\Qt5.7.0\5.7\mingw53_32\bin\qmake.exe
DEL_FILE = del
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
COPY = copy /y
COPY_FILE = copy /y
COPY_DIR = xcopy /s /q /y /i
INSTALL_FILE = copy /y
INSTALL_PROGRAM = copy /y
INSTALL_DIR = xcopy /s /q /y /i
DEL_FILE = del
SYMLINK = $(QMAKE) -install ln -f -s
DEL_DIR = rmdir
MOVE = move
SUBTARGETS = \
release \
debug ......

3.运行make找不到命令,发现安装目录下有一个mingw32-make.exe猜测此文件即是make文件,添加环境变量
运行命令mingw32-make
结果报错,g++命令无法识别,再继续在安装目录下找到g++.exe添加环境变量,
继续运行mingw32-make,报错mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory

D:\QT\helloQt>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'D:/QT/helloQt'
g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=gnu++11 -frtti -Wall -Wextra -f
exceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEE
DS_QMAIN -I. -I. -I..\..\ProgramFilies\Qt5.7.0\5.7\mingw53_32\include -I..\..\Pr
ogramFilies\Qt5.7.0\5.7\mingw53_32\include\QtGui -I..\..\ProgramFilies\Qt5.7.0\5
.7\mingw53_32\include\QtANGLE -I..\..\ProgramFilies\Qt5.7.0\5.7\mingw53_32\inclu
de\QtCore -Irelease -I..\..\ProgramFilies\Qt5.7.0\5.7\mingw53_32\mkspecs\win32-g
++ -o release\main.o main.cpp
In file included from main.cpp:1:0:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
compilation terminated.
Makefile.Release:118: recipe for target 'release/main.o' failed
mingw32-make[1]: *** [release/main.o] Error 1
mingw32-make[1]: Leaving directory 'D:/QT/helloQt'
Makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2

找不到QMainWindow头文件,此时无从下手,此helloQt工程是用IDE创建的并且编译没问题,不过此时我再次使用IDE编译发现报同样的错误mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
郁闷之极,怎么会找不到这个文件
...
此时又重新建一个工程对比文件发现IDE生成的helloQt.pro文件有差别,IDE生成的helloQt.pro文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2016-10-15T18:10:09
#
#------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = qt_empty
TEMPLATE = app SOURCES += main.cpp\
mainwindow.cpp HEADERS += mainwindow.h

比较发现命令行qmake -project生成的文件helloQt.pro少两行
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
添加完这两行之后运行mingw32-make 编译成功生成helloQt.exe
完美!!!
运行正常!!!
后话:
在仔细思考之后发现这两段文字中的粗体部分,平台无关与平台相关,
1.在命令提示符下,进入hello目录,输入如下命令,生成一个与平台无关hello.pro:
qmake -project
2.然后,键入如下命令,从这个项目生成一个与平台相关的makefile文件:
可能正是这两句话导致我出错,因为我是在windows下运行生成了平台无关的hello.pro文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
再查阅资料(.pro文件命令格式)发现
QT:指定工程索要使用的QT模块(默认的是core gui,对应于QtCore和QtGui模块)
查阅QT帮助文档
QMainWindow Class
The QMainWindow class provides a main application window. More...
|
Header: |
#include <QMainWindow> |
|
qmake: |
QT += widgets |
|
Inherits: |
发现类QMainWindow继承自QWidget,所以需要添加widgets模块
所以问题根因一步步揭晓:
1.少添加core gui 模块与widgets模块 同时还可以进行版本判断。
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 如有问题欢迎各路大神进行指点...不吝赐教
Windows下使用MakeFile(Mingw)文件的更多相关文章
- 关于windows下的makefile学习
文中部分引用自:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=408225 windows下makefile环境配置见于:http ...
- Windows 下的 Makefile 编写
Windows 下的 Makefile 编写(一)Makefile的基本规则 作者:cntrump Makefile对于很多人来说是陌生的,特别是习惯于使用 IDE 的人来说,似乎没有听说过 Make ...
- windows下编辑过的文件在Linux下用vi打开行尾会多出一个^M符号
一般情况下,windows下编辑过的文件在Linux下用vi打开行尾会多出一个^M符号,如下图: 这是因为Windows等操作系统用的文本换行符和UNIX/Linux操作系统用的不同,Windows系 ...
- windows下自动删除过期文件的脚本
windows下自动删除过期文件的脚本 前言: 比如日志文件每天都产生,时间长了就会有很大的一堆垃圾.整理一下 定时删除文件的方法. 正文: Windows: 定时删除tomcat日志和缓存.可以保留 ...
- Python Windows下打包成exe文件
Python Windows 下打包成exe文件,使用PyInstaller 软件环境: 1.OS:Win10 64 位 2.Python 3.7 3.安装PyInstaller 先检查是否已安装Py ...
- windows下快速修改host文件
windows下快速修改host文件 win+r 输入 notepad c:\Windows\System32\drivers\etc\hosts
- 【Linux】windows下编写的脚本文件,放到Linux中无法识别格式
注意:我启动的时候遇到脚本错误 » sh startup.sh -m standalone tanghuang@bogon : command not found : command not foun ...
- windows下右键新建md文件
windows下右键新建md文件 打开注册表 win键+R打开运行对话框, 输入regedit, 打开注册表编辑器. 修改注册表 在磁盘的任意位置新建一个文件, 后缀名为reg, 并写入一下内容 [H ...
- windows下安装phpcms html/ 文件夹不可写的一种错误以及解决方法
朋友安装phpcms时遇到奇葩问题,环境搭建在windows7中,竟然出现 html/ 和 phpsso_server/caches/文件夹不可写问题(如图) 在windows下出现这种权限的问题真不 ...
随机推荐
- js备忘录_2
JS函数的参数在function内可以用arguments对象来获取. 转化为数组:var arr=Array.prototype.slice.call(arguments,0); Array有两个: ...
- informix数据库知识积累
一.嵌套查询 informix子查询:嵌套查询(1)select first 20 * from (select first 40 * from hlrquery_log order by id de ...
- HUSTM 1601 - Shepherd
题目描述 Hehe keeps a flock of sheep, numbered from 1 to n and each with a weight wi. To keep the sheep ...
- thread safe
computer science J. Glenn Brookshear with contributions from David T. SmithIndiana University of Pen ...
- LDAP summary-- Python ldap
A DN is comprised of a series of RDNs (Relative Distinguished Names) found by walking UP the tree (D ...
- python MD5步骤
https://www.cnblogs.com/zipon/p/8340720.html import hashlib def get_token(): md5str = "abc" ...
- Mysql 时间类型精度截取的bug
mysql-connector-java版本升级出现的一次问题.涉及到了时间精度的截取和四舍五入. 首先了解一点,timestamp,datetime如果不指定精度,默认的精度是秒. 当mysql-c ...
- IDEA的快捷键和相关设置
快捷键 Shift + Shift: 查找一切 Alt + /: 代码提示(需要修改) Ctrl + Alt + F12: 打开文件所在磁盘位置 Alt + F12: 打开终端 Alt + Ins ...
- servlet输出请求头
1.参考 Enumeration headerNames = req.getHeaderNames(); while(headerNames.hasMoreElements()) { String h ...
- mysql 内置功能 触发器 实验
#准备表命令表 CREATE TABLE cmd ( id INT PRIMARY KEY auto_increment, ), priv ), cmd ), sub_time datetime, # ...