.NET Framework Developer Center > .NET Development Forums > MSBuild > Slow c++ builds with VS2008 / msbuild
Ask a questionAsk a question
 

AnswerSlow c++ builds with VS2008 / msbuild

  • Wednesday, October 14, 2009 8:14 PMChris 4F27446F6E6E656C6C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I noticed our c++ project builds with either VS2008 / msbuild are 3x to 5x slower than with VS2005.  It turns out with that most of our c++ projects are not using precompiled headers (when building with 2008 or with 2005).  This appears to be a bug with 2008.  Using filemon, you can see lots of STL header file searches in rather odd directories before finding them in the expected location, this occurs for every single .cpp file being built.  Enabling precompiled headers solves the problem, the builds go must faster in 2008.

    Has anyone seen this before, and better still, is there a workaround that doesn't require enabling precompiled headers?

    Many thanks,
    -Chris O

Answers

  • Thursday, October 15, 2009 2:25 PMChris 4F27446F6E6E656C6C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello,

    Filemon output for one such header path lookup:

    D:\src\srcmain\Base\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Common\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Model\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Image\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Build\DTK\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Server\Implementation\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft Visual Studio 9.0\VC\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Attributes: A   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Options: Open  Access: All   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    NOT A DIRECTORY    Options: Open Directory  Access: All   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Offset: 0 Length: 28672   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS       

    This occurs for *many* sdk headers for each single .cpp file being compiled.

    Tools / Options / Projects and Solutions / VC++ Directories / Show directories for: Include files:
    $(VCInstallDir)include
    $(VCInsallDir)atlmfc\include
    $(WindowsSdkDir)\include
    $(FrameworkSDKDir)include

    The env vars:
    VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 9.0\VC
    WindowsSdkDir=C:\Program Files\Microsoft SDKs\Windows\v6.0A\
    No FrameworkSDKDir defined as an env var.

    So why is cl.exe searching the above d:\src\srcmain\* dirs for SDK headers?  That doesn't make any sense according to the 4 include file search paths.  But wait a second this is odd (or maybe I'm odd ;-) the above 6 d:\src\srcmain\* dirs exactly match the Additional Include Directories for the vcproj I was building.  So cl.exe appears to be searching my Additional Include Directories for Windows SDK headers?  This didn't happen with VS2005, I had the same vcproj settings.

    Many thanks for your help,
    -Chris O
  • Thursday, October 22, 2009 8:23 AMHongye SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Sorry for the delayed response, Chris.

    It is strange that VS 2005 doesn't search for Additional Include Directories, because according to MSDN documentation, both the C++ compiler 2.0 and 3.5 will search directories in following orders:

    1. Directories containing the source file.

    2. Directories specified with the /I option, in the order that CL encounters them.

    3. Directories specified in the INCLUDE environment variable.

     

    You can change their orders to have a better compile performance.

    Hope it helps.

    The directories set in VS options page will be put into Include environment variable when compiling.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Thursday, October 15, 2009 8:00 AMHongye SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Chris,

    Can you please copy the searched paths from filemon to here?

    The header file search paths can be configurable in VS. You can configure it by Tools / Options / Projects and Solutions / VC++ Directories / Show directories for: Include files

    You should be able to view a list of file paths. Please let me know what they are.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Thursday, October 15, 2009 2:25 PMChris 4F27446F6E6E656C6C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello,

    Filemon output for one such header path lookup:

    D:\src\srcmain\Base\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Common\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Model\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Image\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Build\DTK\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    D:\src\srcmain\Server\Implementation\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft Visual Studio 9.0\VC\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\pshpack1.h    FILE NOT FOUND    Attributes: Error   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Attributes: A   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Options: Open  Access: All   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    NOT A DIRECTORY    Options: Open Directory  Access: All   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS    Offset: 0 Length: 28672   
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\pshpack1.h    SUCCESS       

    This occurs for *many* sdk headers for each single .cpp file being compiled.

    Tools / Options / Projects and Solutions / VC++ Directories / Show directories for: Include files:
    $(VCInstallDir)include
    $(VCInsallDir)atlmfc\include
    $(WindowsSdkDir)\include
    $(FrameworkSDKDir)include

    The env vars:
    VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 9.0\VC
    WindowsSdkDir=C:\Program Files\Microsoft SDKs\Windows\v6.0A\
    No FrameworkSDKDir defined as an env var.

    So why is cl.exe searching the above d:\src\srcmain\* dirs for SDK headers?  That doesn't make any sense according to the 4 include file search paths.  But wait a second this is odd (or maybe I'm odd ;-) the above 6 d:\src\srcmain\* dirs exactly match the Additional Include Directories for the vcproj I was building.  So cl.exe appears to be searching my Additional Include Directories for Windows SDK headers?  This didn't happen with VS2005, I had the same vcproj settings.

    Many thanks for your help,
    -Chris O
  • Thursday, October 22, 2009 8:23 AMHongye SunMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Sorry for the delayed response, Chris.

    It is strange that VS 2005 doesn't search for Additional Include Directories, because according to MSDN documentation, both the C++ compiler 2.0 and 3.5 will search directories in following orders:

    1. Directories containing the source file.

    2. Directories specified with the /I option, in the order that CL encounters them.

    3. Directories specified in the INCLUDE environment variable.

     

    You can change their orders to have a better compile performance.

    Hope it helps.

    The directories set in VS options page will be put into Include environment variable when compiling.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Wednesday, November 04, 2009 12:07 PMDavidTM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Chris

    Please will you give us your conclusion for this issue? I am also finding that VS2008 builds are slower than VS2005 builds, for my C++ project. Any advice would be appreciated.

    David
    David
  • Thursday, November 05, 2009 2:39 PMChris 4F27446F6E6E656C6C Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi David,

    So far no luck, but I was looking for an easy alternative to enabling precompiled headers on the C++ projects.  However, for our projects, enabling precompiled headers works for us; we do get the same build times as with VS2005.  But there are still 70+ projects (and source files) to go.  Certainly doable, but will take a little time.

    As far as explaining the difference between 2005 and 2008 compilers, one could try:  use the /showIncludes switch on both the 2005 and 2008 projects and see if there is anything obvious.

    Hope this helps.
    -Chris O
  • Wednesday, November 11, 2009 9:50 AMZoli1313 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Chris,

    we are having the same problem, vc++ 2008 compilation is _really_ slower in our project than vc++ 2005 was. Something like 3 hours vs 10 hours.
    We don't use precompiled headers neither.
    Let us know if we found something...now I am going to investigate these include folder issues.

    Zoltan