Parallel compilation for projects with dependencie

2020-03-31 08:12发布

问题:

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.

回答1:

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)

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.

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.

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