从头开始为使用Qt的应用程序制作简约的构建文件
Making a minimalistic build file for a Qt-using application from scratch
出于纯粹的教育目的,我想学习如何从头开始创建自己的QT Makefile。
我已经成功地使用了QMake,但我仍然想学习如何制作一个非常简单的Makefile来运行一个基本的QT应用程序。
这是我想要使用 Makefile 编译的代码:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow m;
m.show();
return a.exec();
}
我没有任何特殊要求,也不需要任何特殊的原生包装。
是的!那是一次巨大的学习经历。:)
这是我创建的最小生成文件。
# In the first two lines, I define the source (.cpp) file and the desired output file to be created (./hello)
SOURCE = hello.cpp
OUTPUT = hello
# This variable is used as a quick reference to the QT install path. This is my custom install directory on Mac OS X.
QT_INSTALL_PATH = /usr/local/qt/5.9.1/clang_64
# This is where you would provide the proper includes depending on your project's needs
INCLUDES = -I$(QT_INSTALL_PATH)/lib/QtWidgets.framework/Headers
#This is the RPATH. To be honest, I am not completely sure of what it does, but it is neccesary.
RPATH = -Wl,-rpath,$(QT_INSTALL_PATH)/lib
#Here is where you link your frameworks
FRAMEWORKS = -F$(QT_INSTALL_PATH)/lib -framework QtCore -framework QtWidgets
# The main action that happens when you type "make"
all:
# We run the g++ command and make sure we use c++11 with the second argument. Then after that, we simply plugin in our previous variables.
g++ -std=c++11 $(SOURCE) $(INCLUDES) $(FRAMEWORKS) $(RPATH) -o $(OUTPUT)
如果您想知道,这是我的hello.cpp
文件。这是一个非常基本的程序,只导入QtWidgets
。
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(320, 240);
window.show();
window.setWindowTitle(QApplication::translate("toplevel", "Welcome to QT!"));
return app.exec();
}
这很有趣,我确实学到了很多关于QT程序如何编译的知识。但是,将来我绝对计划坚持使用 qmake,因为它是一个非常棒的工具。
相关文章:
- 如何从构建 libgpio.so 的生成文件构建libgpio.a
- 为多个测试文件构建可执行文件
- 在QMAKE中编译之前,如何使用可执行文件构建多个标头文件
- 从同一文件构建基类和继承类
- cmake:如何迭代目录中的所有源文件并将每个文件构建到可执行文件中
- MEX文件构建具有八度的构建(包装纸问题)
- 通过解析文件构建逻辑语句
- C++ 如何从.dat文件构建字符串的 2D 矩阵?5 列 x 行
- 使用其他文件构建 gcc 插件
- 从文件构建有向图
- 仅使用 DLL *.h 头文件构建(compile.link)应用程序代码,并在运行时加载 DLL 实现(显式链接)
- 使用两个文本文件构建链表
- 从PSD文件构建层comps
- 如何从多个c++文件构建二进制文件
- Eclipse:没有什么要为文件构建的
- MATLAB mex文件构建成功,但没有显示任何内容
- Android OS框架-将单个可执行文件构建为共享对象
- 当尝试从使用makefile生成的目标文件构建时,c++链接器错误.在我刚建立的时候不会发生
- 为什么Xcode 4.2为.cpp文件应用C文件构建规则脚本?
- Matlab Mex文件构建:代码更改不再影响mex文件