Parallel compilation for projects with dependencies on each other in Visual studio

Glen Sand 31 Reputation points
2021-08-03T10:40:50.767+00:00

In my company, we are using Visual Studio 2019 and we would like to reduce the build times of our C++ solution. It is about 21 projects and it takes roughly 8.5 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. Also 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, the 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 a .exe). Is there a way to achieve this?

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2021-08-04T02:06:36.753+00:00

    Hi,

    The /MP option causes the compiler to create one or more copies of itself, each in a separate process. As far as I'm concerned, this is based on each project, and this will not let all projects build in parallel. To do that you have to pass in -M[:num] or -maxcpucount (max cpu count) to msbuild.exe. For more details, I suggest you could refer to the Doc: https://learn.microsoft.com/zh-cn/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019&redirectedfrom=MSDN&viewFallbackFrom=vs-2015

    I am wondering if there is a way to make projects with dependencies on each other compile in parallel.

    If the two projects that depend on each other, are in the same solution and the dependencies between each other are clearly marked, then the cpp files can be compiled at the same time, but not linked at the same time. The linking must occur in order of how they depend on one another.

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.