Last active
February 26, 2018 13:02
-
-
Save lixingcong/a6fddb5fc851c43cc215d465da1e0ee7 to your computer and use it in GitHub Desktop.
QT下的qmake的Makefile模板
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# C++ objects and libs | |
*.slo | |
*.lo | |
*.o | |
*.a | |
*.la | |
*.lai | |
*.so | |
*.dll | |
*.dylib | |
# Qt-es | |
object_script.*.Release | |
object_script.*.Debug | |
*_plugin_import.cpp | |
/.qmake.cache | |
/.qmake.stash | |
*.pro.user | |
*.pro.user.* | |
*.qbs.user | |
*.qbs.user.* | |
*.moc | |
moc_*.cpp | |
moc_*.h | |
qrc_*.cpp | |
ui_*.h | |
*.qmlc | |
*.jsc | |
*build-* | |
# Qt unit tests | |
target_wrapper.* | |
# QtCreator | |
*.autosave | |
# QtCreator Qml | |
*.qmlproject.user | |
*.qmlproject.user.* | |
# QtCreator CMake | |
CMakeLists.txt.user* | |
# my build dir | |
build/* | |
!build/.noempty | |
*.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROJECT_NAME=qt-demo | |
QTMAKE_MK=$(PROJECT_NAME)-qtmake.mk | |
PROJECT_FILE=$(PROJECT_NAME).pro | |
all: $(QTMAKE_MK) | |
$(MAKE) -f $^ | |
$(QTMAKE_MK): $(PROJECT_FILE) | |
qmake -r -o $@ $^ | |
.PHONY: clean | |
clean: $(QTMAKE_MK) | |
$(MAKE) -f $^ clean | |
rm -rf $^ | |
.PHONY: install | |
install: $(QTMAKE_MK) | |
$(MAKE) -f $^ install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QT += core gui | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
TARGET = qt-demo | |
TEMPLATE = app | |
# You must create the dir 'build' first | |
DESTDIR=build | |
OBJECTS_DIR=build | |
MOC_DIR=build | |
UI_DIR=build | |
SOURCES += main.cpp\ | |
mainwindow.cpp\ | |
subdir/People.cpp | |
HEADERS += mainwindow.h\ | |
subdir/People.h | |
FORMS += mainwindow.ui |
添加至Eclipse工程:
关键点:
- 注意开启C++11的语法高亮特性
- 添加宏定义QT_CORE_LIB等,根据make命令后的宏添加
不同平台有不同设置:
对于Linux,仅需在Bash中执行一次make,观察make之后的g++的inlude目录,逐一添加到Eclipse的Include Paths中
对于Windows,比较复杂:
- 下载mingw32(或直接用QT安装的MinGW),在Windows中指定PATH环境变量
- 建立Eclipse工程为Toolchain: MinGW的C++工程(Makefile with exist code)
- 工程设置:指定MINGW_HOME变量为上述的PATH_QT_MINGW上一级
- 工程设置:指定rm命令(用于clean)的PATH,例如git自带的rm命令位于
F:\Program Files\Git\usr\bin
- 工程设置:编译命令为mingw32-make
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如果是windows平台,需要添加两个PATH,建议使用git for windows的bash
使用source命令执行