在Visual Studio中对相互依赖的项目进行并行编译 [英] Parallel compilation for projects with dependencies on each other in Visual studio

查看:317
本文介绍了在Visual Studio中对相互依赖的项目进行并行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的公司中,我们正在使用Visual Studio 2013,我们希望减少C ++解决方案的构建时间。它大约有55个项目,调试构建大约需要20分钟,而发行版本则需要更多时间。我想知道是否有一种方法可以使相互依赖的项目并行 编译 。我已经知道并利用多进程编译(/ MP标志)。实际上,解决方案中的每个项目都是使用多个内核构建的。当两个项目(例如A和B)彼此不依赖时,它们并行构建。但是,使用我们当前的设置,如果A依赖于B,则必须在A开始之前完成B的构建。据我了解,A中的文件甚至可以在B完成之前就开始编译,并且只有A的链接才真正等到B完成(假设A生成.dll或.exe)。有没有办法做到这一点?如果在VS2013中不可能,我们很快计划升级到VS2017,因此有关VS2017的建议也很有用。

In my company we are using Visual Studio 2013 and we would like to reduce the build times of our C++ solution. It is about 55 projects and it takes roughly 20 minutes for a debug build and a lot more for a release build. I am wondering if there is a way to make projects with dependencies on each other compile in parallel. I am already aware and make use of multiprocess compilation (/MP flag). Indeed, each project in the solution is built using multiple cores. Aslo when two projects, let's say A and B, don't depend on each other they build in parallel. However with our current settings, if A depends on B, the build of B has to complete before A starts. As far as I understand, compilation of files in A can start even before B finishes, and only linking of A has to really wait until B finishes (let's assume that A generates either a .dll or an .exe). Is there a way to achieve this? If not possible in VS2013, we soon plan to upgrade to VS2017, so suggestions about VS2017 are also useful.

推荐答案

C ++编译器开关/ MP用于并行编译cpp文件。这是基于每个项目的。但是,这不会使所有项目并行构建。为此,您必须将-M [:num]或-maxcpucount(最大CPU计数)传递给msbuild.exe。 (请参见 https://msdn.microsoft.com/en-us/library/ ms164311.aspx 了解详情)

The C++ compiler switch /MP is for compiling cpp files in parallel. This is on a per project basis. This will not however get all the projects to build in parallel. To do that you have to pass in -M[:num] or -maxcpucount (max cpu count) to msbuild.exe. (see https://msdn.microsoft.com/en-us/library/ms164311.aspx for details)

回答第一个问题:是否有一种方法可以使相互依赖的项目并行编译 。
答案有点。
如果两个相互依赖的项目处于一个解决方案中,并且彼此之间的依赖关系被明确标记,则cpp文件可以同时编译,但不能同时链接。链接必须按照它们彼此依赖的顺序进行。

In answer to your first question: "if there is a way to make projects with dependencies on each other compile in parallel". The answer is kinda. If the two projects that depend on each other, are in a solution and the dependencies between each other are clearly marked, then the cpp files can compile simultaneously, but not link simultaneously. The linking must occur in order of how they depend on one another.

因此,如果您想使事情更快地编译,通常您希望项目之间的依赖关系尽可能少。但是还有其他方法可以使C ++更快地编译。

So in general you want as few dependencies as possible between your projects if you want to make things compile faster. But there are other ways to make C++ compile faster.

至于VS 2017,请运行不要走路进行升级。

As for VS 2017, Run don't Walk to upgrade.

这篇关于在Visual Studio中对相互依赖的项目进行并行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆