views:

138

answers:

1

I have an C++/CLI assembly consisting of approximately 50 source files. The code in this assembly links statically to a number of C++ libraries to do various 'heavy-lifiting' type tasks.

I am using Visual Studio 8 (2005) SP1 to build this assembly.

Building just this assembly (without dependencies, etc) via 'Project Only'->'Rebuild Only' takes about 4.5 minutes on a decent dual-core machine. Below is the abbreviated build output annotated with approximate times:

Compiling...
(file 0)
(file 1)
...
(file N)                   // About 2 min total to compile all files
Linking...                 // About 12s
Generating Code            // 42s
Finished Generating Code   // < 1s
Embedding Manifest         // < 1s
Generating Code            // 30s
Finished Generating Code
(15 seconds of nothing)
Done

How should I begin debugging why this assembly is taking so long to build? The compile and link times, while not great, are probably about what I'd expect for a project of this size. What concerns me is the fact that I'm seeing two 'Generating Code' steps, each taking much longer than most other projects.

My first guess was that this has to do with the amount of unmanaged code that is linked into the assembly. However, I have several managed applications projects that use just as much native code, and the build times are very reasonable.

Does anyone know what exactly could cause two 'Generating Code' steps that take so long? Is there a project setting I'm missing?

+1  A: 

Do you use pre-compiled headers for your project? Managed C++ has support for it the same way unmanaged C++ does. To switch your project to pre-compiled headers:

See this article (scroll down to "Precompiled Header" section) for in-depth details.

  • Make sure that every single .cpp file begins with #include "xxxx", where xxxx.h is some header file that includes all the common header files used in your project.
  • Create an xxxx.cpp file that only includes the xxxx.h file, and has no other code
  • In the VS compile settings for the whole project, for all configurations (build & release), in the pre-compile header sections, make the whole project use the xxxx.h precompiled header.
  • In the VS compile settings for the xxxx.cpp file only, for all configurations (build & release), in the pre-compile header sections, set it to "generate precompiled header".

Compiling the project should now take a fraction of the previous build time.

Yurik