C++ 为什么 Qt 使用自己的 make 工具 qmake?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1368534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:43:08  来源:igfitidea点击:

Why does Qt use its own make tool, qmake?

c++qtcross-platformqmake

提问by Trevor Boyd Smith

I just started using Qtand noticed that it uses its own make tool, qmake.

我刚开始使用Qt并注意到它使用自己的 make 工具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 GCCC++ compiler?
  • 为什么 Qt 使用自己的 make 工具?
  • 有什么特别的东西可以阻止它使用标准的 make 工具吗?
  • qmake 会调用GCCC++ 编译器吗?

回答by Thomi

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).

Qt 使用 qmake 透明地支持 Qt 的各种插件,包括“moc,元对象编译器”(提供信号和槽),“uic,ui 编译器”(从 .ui 设计器文件创建头文件),“rcc,资源编译器”(编译资源)。

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.

没有什么可以阻止您使用您想要的任何构建系统。然而,还有很多工作要做。例如,您需要对包含具有信号或槽的类的每个头文件运行“moc”。一般不推荐使用,特别是对于刚开始使用 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 不直接调用 g++/gcc。相反,qmake 在您当前的平台上创建本机 make 文件。在linux下它创建标准的GNU make文件,在windows下它可以生成visual studio make文件,在Mac OS X下它可以生成XCode工程文件。然后调用您的本机构建系统(GNU make、MS NMake、xcodebuild 或其他),它将调用您的本机编译器(g++/gcc 或其他)。

回答by Game Coder

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.

在我看来,qmake 对于简单的项目很酷(你可以只使用 qmake -project; qmake; make),但是对于大型项目来说很糟糕并且没有足够的文档记录。尤其是qmake的configure功能简直就是个笑话。

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 :)

我所知道的最好的构建系统是 CMake 和 Waf(基于 Python)。在我自己的 Qt 项目中,我使用 CMake 来完成这项工作。就像 KDE 的人一样 :)

回答by Ron Warholic

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 Compileror MOC.

为了支持它的信号/槽系统,Qt 依赖于一个特殊的预处理器和编译器,它生成执行大部分处理的中间对象。他们将其称为元对象编译器MOC

See Qt 5 Documentation: Using the Meta-Object Compilerfor details.

有关详细信息,请参阅Qt 5 文档:使用元对象编译器

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.

MOC(以及其他一些中间工具)与qmake; 一个构建自动化工具,它以您的本机格式(VC++、g++ 等)生成 Makefile,将 MOC 生成的中间文件以及所有源文件构建到最终的可执行文件中。

回答by Brian Gianforcaro

qmakeis designed to be cross platform and flexible. It can compatible with Microsoft Visual Studio and Xcode.

qmake被设计为跨平台和灵活的。它可以与 Microsoft Visual Studio 和 Xcode 兼容。

You can find it all in the qmake Manual.

您可以在qmake 手册中找到所有内容。

qmake generates a Makefile based on the information in a project file. Project files are created by the developer, and are usually simple, but more sophisticated project files can be created for complex projects. qmake contains additional features to support development with Qt, automatically including build rules for moc and uic. qmake can also generate projects for Microsoft Visual studio without requiring the developer to change the project file.

qmake 根据项目文件中的信息生成 Makefile。项目文件由开发人员创建,通常很简单,但可以为复杂的项目创建更复杂的项目文件。qmake 包含支持使用 Qt 开发的附加功能,自动包括 moc 和 uic 的构建规则。qmake 还可以为 Microsoft Visual Studio 生成项目,而无需开发人员更改项目文件。

回答by Dirk Eddelbuettel

In order

为了

a) because it does lot behind the scenes for you

a) 因为它在幕后为你做了很多

b) yes, see a)

b) 是的,见 a)

c) yes, it does call g++ (but can support other compilers if you have them)

c) 是的,它确实调用了 g++(但可以支持其他编译器,如果你有的话)