如何在 QTCreator 中使用 mingw 在多核上进行编译
我的 Windows 桌面上有一个四核 i7 CPU。我试图让 mingw32-make 使用尽可能多的核心进行编译。我已将 -j8 添加到“构建设置”->“构建步骤”下的“生成参数”字段中。 mingw32-make 似乎完全忽略了该选项,因为我没有从中获得任何速度改进。当我在任务管理器中查看 CPU 使用率时,它保持在 13%,并且我只看到一个 g++ 实例在运行。
目前,使用 mingw 重建整个项目需要整整 3 分钟。使用 MSVC 重建它只需 15 秒。
供您参考,我在项目设置中启用了预编译头选项。这也使得 VC 的处理速度更快。但我还没有看到 mingw 预编译头的好处。
如果您曾经让 mingw 从 QTCreator 并行编译多个源文件,请分享您的评论。谢谢!
I have a quad-core i7 CPU on my windows desktop. I am trying to get mingw32-make to compile using as many core as possible. I have added -j8 into the "Make Arguments" fields under Build Settings->Build Steps. mingw32-make seems to completely ignore the option since I don't get any speed improvement out of that. When I view the CPU usage in task manager, it stays at 13% and I only see one instance of g++ running.
Right now, rebuilding the whole project using mingw takes 3 full minutes. Rebuilding it using MSVC takes only 15 seconds.
For your information, I have enabled the precompiled header option in the project settings. That makes things a lot quicker with VC as well. But I am still yet to see the benefit of precompiled header with mingw.
Please share your comments if you have ever got mingw to compile multiple source files in parallel from QTCreator. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这就是我所做的。
在工具-> Qt Creator 中的选项菜单,在“构建和运行”部分下,有一个选项显示“使用 jom 而不是 nmake”。我选中了该框,但没有任何改变。因此,我转到项目的构建设置,在构建步骤类别下有一个“Make”项。展开详细信息,您将找到“Override mingw32-make.exe:”项。我将“C:\QtSDK\QtCreator\bin\jom.exe”粘贴到那里,突然间我开始使用多个内核进行构建。
在 Qt Creator 2.4.1 上为我工作。尝试一下。
Here's what I did.
In the Tools -> Options menu in Qt Creator, under the "Build and Run" section there's an option that says "Use jom instead of nmake". I checked that box, but nothing changed. So instead, I went to the project's build settings and under the build steps category there is a "Make" item. Expand the details on that and you'll find a "Override mingw32-make.exe:" item. I pasted "C:\QtSDK\QtCreator\bin\jom.exe" in there, and suddenly I was building with multiple cores.
Worked for me on Qt Creator 2.4.1. Give it a try.
由于 Win32 上的 GNU Make 的限制,
-j8
可能无法正常工作。尝试将
-j
放入 make 参数字段。这告诉 Make 生成尽可能多的编译进程——如果你有足够的 RAM 和 CPU 来处理它,它应该比单个编译更快。不幸的是,这是仅有的两个选项(不修改 Makefile):
-j1
或无限制-j
完整详细信息:Win32 上的 GNU Make 不支持作业服务器,因此父 Make 进程无法跟踪任何子 Make 生成的编译进程的数量。为了安全起见,子 Make 仅使用
-j1
运行。我相信 qmake/Qt Creator 生成的 Makefile 使用多层 Makefile。我首先通过 Microchip 的 MPLAB X IDE 解决了这个问题,请查看 此线程了解更多信息此引用来自与 GNU Make 一起分发的 README.W32
-j8
probably isn't working because of a limitation in GNU Make on Win32.Try putting just
-j
into the make arguments field. That tells Make to spawn as many compile processes as it can--if you have enough RAM and CPU to handle that, it should be faster than a single compile.Unfortunately these are the only two options (without modifying the Makefiles): either
-j1
, or unlimited-j
Full details: GNU Make on Win32 doesn't support the job server, so a parent Make process can't track the number of compile processes spawned by any sub-Make's. To be safe, the sub-Make's only run with
-j1
. I believe qmake/Qt Creator's generated Makefiles use multiple layers of Makefiles. I first figured out this issue with Microchip's MPLAB X IDE, check out this thread for more infoThis quote is from README.W32 distributed with GNU Make
添加
-j9
(将9
替换为NUMBER_OF_PROCESSORS
(Windows)/$(nproc)
(Linux) 的值以及一个 - 这是最佳的)到qmake\generators\makefile.cpp 中的所有行(你自己找到它)。
结果是
使用适当的参数运行
configure.exe
(!以及附加的-qmake -dont-process
以避免生成大量 makefile!)。问题是在“调试和发布”构建期间您会得到两组进程。因此,生成的进程总数超过 18 个。
Add
-j9
(replace9
to value ofNUMBER_OF_PROCESSORS
(Windows)/$(nproc)
(Linux) plus one — this is optimal) to alllines in qmake\generators\makefile.cpp (find it yourself).
It results as
then run
configure.exe
with proper parametres (!and additional-qmake -dont-process
to avoid generation abundance of makefiles!).The problem is that you get two sets of processes during "debug and release" build. Thereby, total count of processes spawned is 18+.
使用
MAKE_COMMAND
环境变量:Use
MAKE_COMMAND
environment variable:在 Qt Creator 中,转到“项目”->“构建&运行->您特定的 MinGW 构建设置 ->构建环境(位于常规/构建步骤/清理步骤下面的屏幕上..),然后添加变量
MAKEFLAGS
并将其设置为-j8
。我在我的两核机器上使用-j4
和 QtCreator 4.4.1 以及 MinGW 5.3.0 进行了测试。编译时,我的处理器以 100% 的性能运行,如任务管理器中所示。如果没有这个选项,它大约是 25%,所以我认为它完全按照预期工作。现在构建速度要快得多。In Qt Creator go to Projects -> Build & Run -> your specific MinGW build setup -> Build Environment (this is on the screen below General / Build steps / Clean steps..) and then add a variable
MAKEFLAGS
and set it to-j8
. I tested this on my two core machine with-j4
and QtCreator 4.4.1 and with MinGW 5.3.0. When compiling my processor runs at 100 % performance as can be seen in the Task Manager. Without this option it was about 25 % so I assume it works exactly as expected. The build is now much faster.-j 是可行的方法,不幸的是,对我来说,该项目太大了,它耗尽了我所有的可用内存,并且我的计算机冻结了,所以请注意这一点。布伦丹说,例如,不可能只使用一半的核心,如果这是真的,那就太遗憾了。
-j is the way to go, unfortunately for me the project is so large it uses up all of my available memory and my computer freezes, so be aware of that. Brendan said there is no way to only use half your cores for example which is a pity if true.
问题是原来的 make 没有 jobserver 支持。所以mingw32端口也没有它。但此后已添加。我相信具有“正确”作业服务器支持的最旧版本是 3.82.90。您可以在下面的链接中找到它。
http://sourceforge.net/项目/mingw/files/MinGW/Extension/make/make-3.82.90-cvs-20120823/
The issue is that the original make does not have jobserver support. So the mingw32 port didn't have it either. It has since been added however. I believe the oldest version with 'correct' jobserver support is 3.82.90. You can find that at the link below.
http://sourceforge.net/projects/mingw/files/MinGW/Extension/make/make-3.82.90-cvs-20120823/