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.
-
Have you considered adopting SCU (single compilation unit) builds? – user7860670 Dec 11 '17 at 19:07
-
I had given it a quick try. To start with, I was getting a lot of compilation errors, e.g. a free function with the same name defined in two source files (i know it sounds bad and i agree it is bad) will result in errors. It is an old codebase with quite a bit of messy code, so it would need effort just to make it compile. I didn't insist to make it work because although it will make full builds fast, partial builds (e.g. change to a single source) file will become slower, probably much slower. – opetroch Dec 11 '17 at 21:11
1 Answers
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.

- 15,637
- 9
- 61
- 77
-
Thanks for the reply. Could you please explain what you mean when you say "the dependencies between each other are clearly marked"? Even if file a.cpp in project A makes use of a class implemented in file b.cpp of project B, I don't see why a.cpp and b.cpp cannot compile in parallel (access to the header b.hpp should be enough for a.cpp to compile). Removing dependencies between projects would be ideal, unfortunately I have tried and failed to make serious progress. – opetroch Dec 11 '17 at 21:39
-
A solution file merely lists what is to be built, and what depends on each other. That is all a solution (*.sln) does. It's not complicated. – C.J. Dec 13 '17 at 22:58