为什么Qt使用自己的make工具qmake?
I just started using Qt and noticed that it uses its own make tool, qmake.
- Why does Qt use its own make tool?
- Is there something special that prevents it from using a standard make tool?
- Does qmake call the GCC C++ compiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Qt 使用 qmake 透明地支持 Qt 的各种插件,包括“moc,元对象编译器”(提供信号和槽)、“uic,ui 编译器”(从 .ui 设计器文件创建头文件)、“rcc” ,资源编译器”(编译资源)。
没有什么可以阻止您使用任何您想要的构建系统。然而,这还有很多工作要做。例如,您需要对包含具有信号或槽的类的每个头文件运行“moc”。一般来说不推荐,特别是对于刚开始使用Qt的人。
QMake 不直接调用 g++/gcc。相反,qmake 在您当前的平台上创建本机 make 文件。在linux下它可以创建标准的GNU make文件,在windows下它可以生成Visual Studio make文件,在Mac OS X下它可以生成XCode项目文件。然后,您调用本机构建系统(GNU make、MS NMake、xcodebuild 或其他),它将调用您的本机编译器(g++/gcc 或其他)。
Qt uses qmake to transparently support Qt's various addons, including "moc, the meta-object compiler" (which provides signals & slots), "uic, the ui compiler" (which creates header files from .ui designer files), "rcc, the resource compiler" (which compiles resources).
There's nothing to stop you using any build system you want. however, it's a lot more work. For example, you need to run "moc" over every header file that contains a class that has signals or slots. In general it's not recommended, especially for someone who's just starting to use Qt.
QMake does not call g++/gcc directly. Instead, qmake creates native make files on your current platform. Under linux it creates standard GNU make files, under windows it can generate visual studio make files, under Mac OS X it can generate XCode project files. You then invoke your native build system (either GNU make, or MS NMake, or xcodebuild or whatever), which will call your native compiler (g++/gcc or whatever).
在我看来,qmake 对于简单的项目来说很酷(你可以只使用 qmake -project; qmake; make),但对于大型项目来说则很糟糕并且没有足够的文档记录。尤其是 qmake 的配置功能就是一个笑话。
我所知道的最好的构建系统是 CMake 和 Waf(基于 Python)。在我自己的 Qt 项目中,我使用 CMake 来完成这项工作。就像 KDE 的人一样 :)
In my opinnion qmake is cool for simple projects (you can just qmake -project; qmake; make), but horrible and not documented enough for largish projects. Especially the configure functionality of qmake is a joke.
The best build systems I know are CMake and Waf (Python -based). In my own Qt-projects I use CMake to do the job. Just like KDE-guys :)
为了支持其信号/槽系统,Qt 依赖于一个特殊的预处理器和编译器来生成完成大部分处理的中间对象。他们将其称为元对象编译器或MOC。
有关详细信息,请参阅 Qt 5 文档:使用元对象编译器。
MOC(以及其他一些中间工具)与 qmake 结合使用;一个构建自动化工具,它以您的本机格式(VC++、g++ 等)生成 Makefile,将 MOC 生成的中间文件以及所有源文件构建到最终的可执行文件中。
To support its signal/slot system Qt relies on a special preprocessor and compiler that generates intermediate objects that do much of the processing. They refer to this as the Meta-Object Compiler or MOC.
See Qt 5 Documentation: Using the Meta-Object Compiler for details.
The MOC (along with a couple of other intermediate tools) works in conjunction with
qmake
; a build automation tool which produces Makefiles in your native format (VC++, g++, etc.) that build the intermediate files generated by the MOC as well as all of your source files into the final executable.qmake 被设计为跨平台且灵活。它可以与 Microsoft Visual Studio 和 Xcode 兼容。
您可以在qmake 手册中找到所有内容。
qmake is designed to be cross platform and flexible. It can compatible with Microsoft Visual Studio and Xcode.
You can find it all in the qmake Manual.
按顺序
a) 因为它在幕后为您做了很多工作
b) 是的,请参阅 a)
c) 是的,它确实调用 g++ (但可以支持其他编译器,如果您有的话)
In order
a) because it does lot behind the scenes for you
b) yes, see a)
c) yes, it does call g++ (but can support other compilers if you have them)
顺便说一下,直到 Qt 5.x(包括在内)之前都是如此。
Qt 6 现在改用 CMake。至少对于构建 Qt 本身来说是这样,但似乎有理由期望 cmake 将被推荐用于构建 Qt 应用程序本身而不是 qmake。特别是因为主要的 qmake 开发人员不再为 Qt 公司工作。
终于有了一个行业标准工具,而不是内部工具:-)
By the way, this was true until Qt 5.x, included.
Qt 6 is now switching to CMake instead. At least for building Qt itself, but it seems reasonable to expect that cmake will then be recommended for building Qt applications themselves rather than qmake. Especially since the lead qmake developer no longer work for the Qt Company.
Finally an industry-standard tool instead of an in-house one :-)