简体   繁体   English

在 Windows 上快速编译 Qt C++

[英]Fast Qt C++ compile on windows

I have a large project that uses the Qt framework and am trying to find the fastest way to compile it on my Windows install.我有一个使用 Qt 框架的大型项目,我正在尝试找到在我的 Windows 安装上编译它的最快方法。

On my linux machine at home I use 3 year old Linux Mint setup with a dual core (the machine is 3 years old not Linux Mint install) , using: make -j2 both cores are used full(ish) and compiles the code relatively quick, around 10 minutes from clean build.在我家里的 linux 机器上,我使用 3 岁的双核 Linux Mint 设置(机器是 3 岁,不是 Linux Mint 安装) ,使用:make -j2 两个内核都使用 full(ish) 并且编译代码相对较快,从干净的构建大约 10 分钟。

However on my work Windows PC which is 2.0 GHz Intel Core 2 Quad (XP) I can never seem to get the compiles to be as fast as my Linux box.然而,在我的工作 Windows PC 上,它是 2.0 GHz Intel Core 2 Quad (XP),我似乎永远无法像我的 Linux 机器一样获得编译速度。 The developer docs for the program recommend using Visual Studio C++ using the project file generated from cmake but that only seems to use one core and takes well over a hour to compile vs about 10 minutes (from clean build) on my Linux install.该程序的开发人员文档建议使用 Visual Studio C++ 使用从 cmake 生成的项目文件,但这似乎只使用一个核心,编译需要一个多小时,而在我的 Linux 安装上大约需要 10 分钟(从干净构建)。

I have tred using jom but even when using all the cores it still takes around an hour and half because it only seems to use small amounts of cpu on each core.我尝试过使用jom,但即使使用所有内核,它仍然需要大约一个半小时,因为它似乎只在每个内核上使用少量 CPU。

Doesn't make sense to me that my old Linux machine builds quick but the quad core just slumps along.对我来说,我的旧 Linux 机器构建得很快,但四核却一直下滑,这对我来说没有意义。

The following have helped the speed of our Windows C++ Qt builds, over the years:多年来,以下内容帮助我们加快了 Windows C++ Qt 构建的速度:

  1. Customised the settings on our anti-virus software, to exclude from scanning the locations of our Source code, object code, and all headers and libraries we are building against (Visual Studio, Qt etc).自定义我们的防病毒软件上的设置,以排除扫描我们的源代码、目标代码以及我们正在构建的所有头文件和库(Visual Studio、Qt 等)的位置。 (There's a separate AV check that gets run overnight, to scan those excluded folders) (有一个单独的 AV 检查可以在一夜之间运行,以扫描那些排除的文件夹)
  2. Ran a comparison of build speeds under various different AV packages.比较了各种不同 AV 包下的构建速度。 (This was several years ago, but as a result, we moved from McAfee to Sophos) (这是几年前的事情,但结果,我们从 McAfee 迁移到了 Sophos)
  3. Made sure all files accessed during the build are on a local disk drive (we used to build against Qt on a network drive, but that killed the build performance)确保在构建期间访问的所有文件都在本地磁盘驱动器上(我们曾经在网络驱动器上针对 Qt 进行构建,但这会降低构建性能)
  4. Made sure that Visual Studio is configured to do multiple compile steps at once: This answer shows various ways of doing that.确保将 Visual Studio 配置为一次执行多个编译步骤: 此答案显示了执行此操作的各种方法
  5. Increased the amount of RAM: we're finding these days that 4 GB is the absolute minimum, for a sizable code base增加了 RAM 量:我们发现现在 4 GB 是绝对最小值,对于相当大的代码库
  6. Switched from static to dynamic linking, to massively shorten link times.从静态链接切换到动态链接,以大幅缩短链接时间。
  7. Moved to new versions of Visual Studio, as MS has improved performance: see this Visual Studio 2010 page , and search for 'Faster Compilation'移至新版本的 Visual Studio,因为 MS 提高了性能:请参阅此Visual Studio 2010 页面,并搜索“更快的编译”

Our Windows builds are still slower than Linux ones, but I can't say that's a fair comparison, as our shared Linux build box is a much higher spec than developer PCs.我们的 Windows 构建仍然比 Linux 慢,但我不能说这是一个公平的比较,因为我们共享的 Linux 构建盒比开发人员 PC 的规格高得多。

(As an aside, if you haven't seen them before, it's worth reading what Jeff Atwood has to say about good configurations for developer PCs: eg the Programmer's Bill of Rights ) (顺便说一句,如果您以前没有见过它们,那么值得一读 Jeff Atwood 关于开发人员 PC 的良好配置的评论:例如程序员权利法案

Update: 25/10/2012更新:25/10/2012

If you are on Visual Studio 2008, with DLL builds, I do not currently recommend moving to Visual Studio 2010 : there is an issue with unnecessary re-linking of dependent projects that absolutely kills developer productivity, at least in a .sln with 20 or so .vcxproj files:如果您使用的是带有 DLL 构建的 Visual Studio 2008,我目前不建议迁移到 Visual Studio 2010 :依赖项目的不必要重新链接存在一个问题,这绝对会降低开发人员的生产力,至少在具有 20 或所以 .vcxproj 文件:

There may be a solution to this - I'll update later, once I've tested it - see Unnecessary relinks of dependent projects when building with Visual Studio 2010 where CORCOR said:可能有一个解决方案 - 我稍后会更新,一旦我测试过它 - 参见使用 Visual Studio 2010 构建时依赖项目的不必要的重新链接,其中 CORCOR 说:

If others have a similar problem:如果其他人也有类似的问题:

Turning off the manifestation creation for the DLL projects and turning it on only for the application project helps!关闭 DLL 项目的表现创建并只为应用程序项目打开它会有所帮助!

With VS2008 this seemed to be no problem.对于 VS2008,这似乎没有问题。

This might be a bit of a workaround, but we use Incredibuild, which distributes the build across multiple machines, which works really well.这可能是一种解决方法,但我们使用 Incredibuild,它将构建分布在多台机器上,效果非常好。 Cuts down our build times from 40 to 10 minutes.将我们的构建时间从 40 分钟缩短到 10 分钟。 (we have 6 developer PCs hooked up to share the workload) (我们连接了 6 台开发人员 PC 来分担工作量)

Visual Studio can compile several projects in parallel, but each single project is compiled sequentially. Visual Studio 可以并行编译多个项目,但每个项目都是按顺序编译的。 So if you compile a solution with 2 projects then two processes will be launched in parallel, but if you have just one project then just one process will start and it will compile your source sequentially.因此,如果您编译一个包含 2 个项目的解决方案,那么两个进程将并行启动,但如果您只有一个项目,那么将只启动一个进程,它将按顺序编译您的源代码。

If you use MingW, you can follow this thread: http://www.mail-archive.com/qt-creator@trolltech.com/msg00156.html如果你使用 MingW,你可以关注这个帖子: http : //www.mail-archive.com/qt-creator@trolltech.com/msg00156.html

There you will find the solution (install MSys and specify the parameter -j when you launch make in order to specify the number of parallel jobs).在那里您将找到解决方案(安装 MSys 并在启动 make 时指定参数 -j 以指定并行作业的数量)。

An even easier solution is here: http://developer.qt.nokia.com/forums/viewthread/855/ (in QtCreator Tools->Options specify Jom as build tool instead of NMake)一个更简单的解决方案在这里: http : //developer.qt.nokia.com/forums/viewthread/855/ (在 QtCreator Tools->Options 中指定 Jom 作为构建工具而不是 NMake)

I had the same problem.我有同样的问题。 On our machines was a software running that tried to determine the compatibility with Windows 7. This software was logging every start of a software to a database and thereby slowed down the startup of new processes a bit.在我们的机器上运行着一个软件,它试图确定与 Windows 7 的兼容性。该软件将软件的每次启动记录到数据库中,从而稍微减慢了新进程的启动速度。 Since the compiler starts a new process for every file this significantly slowed down the whole compile run.由于编译器为每个文件启动一个新进程,这显着减慢了整个编译运行。

In Visual Studio did you go to:在 Visual Studio 中,您是否去了:

Project -> Properties -> C++ and turned "Multiprocessor Compilation" to Yes ?项目 -> 属性 -> C++ 并将“多处理器编译”变为是? That did the Trick for me turning on Multicore, which should speed it up actually quite much.这对我打开多核很有帮助,实际上应该可以大大加快速度。

I think is best way by splitting your project into multi-projects each project is Static library project join them together by container project which is usually MainWindow class.我认为最好的方法是将您的项目分成多个项目,每个项目都是静态库项目,通过容器项目将它们连接在一起,容器项目通常是 MainWindow 类。 Thus compiling duration will takes a while for first time then it will be short (depending on your modifications).因此,第一次编译持续时间需要一段时间,然后会很短(取决于您的修改)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM