Reputation:
What are the best ways to speed up compilation time in Visual Studio 2005 for a solution containing mainly C++ projects?
Upvotes: 6
Views: 1110
Reputation: 1
Change your Solution Platform on "Any CPU" option which is given on the top of visual stdio then your program build speed will be definitely increased.
Upvotes: 0
Reputation: 54300
#include
's from header files).Upvotes: 3
Reputation: 180145
The solution we've used was IncrediBuild. Just throw more hardware at the problem. In addition to all the developer machines (fairly powerful themselves) we had a number of 4-core servers doing nothing but compiling.
Upvotes: 0
Reputation: 81517
Besides pre-compiling headers, there are number of other things that could be slowing you down:
EDIT Few more thoughts:
Upvotes: 6
Reputation: 8526
At the code level, it's helpful to minimize the amount of headers included by other headers. Repeatedly loading and reading files can have a big impact. Instead, forward declare things wherever possible. For example:
#include <iosfwd>
#include <string>
#include "M.h"
#include "R2.h"
#include "A2.h"
class M2;
class A;
class R;
template<class C> class T;
class X{
M member; // definition of M is required
M2 *member2; // forward declaration is sufficient for pointers & references
public:
// forward declaration of argument type A is sufficient
X(const A &arg);
// definition required for most std templates and specializations
X(const std::string &arg);
// forward declaration of your own templates is usually okay...
void f(T<int> t);
// unless you're defining a new one. The complete definition
// must be present in the header
template<class Z>
void whatever(){
// blah blah
}
R f(); // forward declaration of return type R is sufficient
// definitions of instantiated types R2 and A2 are required
R2 g(A2 arg){
return arg.h();
}
// ostream is forward-declared in iosfwd
friend std::ostream &operator << (std::ostream &o, const X &x);
};
Users of this class will have to #include
whatever files provide the class definitions if they actually call any of X(const A&)
, f(t<int>)
, f()
, or operator <<
.
Templates will almost certainly add to inclusion overhead. This is generally worth their power, in my opinion. When you make your own templates, the complete definition must reside in the header file; it cannot go in a cpp file for separate compilation. Standard templates can't be forward declared, because implementations are allowed to provide additional template parameters (with default arguments) and forward declarations of templates must list all of the template parameters. The iosfwd header forward-declares all of the standard stream templates and classes, among other things. Your own templates can be forward-declared as long as you don't instantiate any specializations.
Precompiled headers can also help, but most compilers limit the quantity that you can include in a source file (Visual Studio limits you to one), so they aren't a panacea.
Upvotes: 3
Reputation: 14471
If you have a lot of projects in the solution remove some of them. If they're referenced as projects you can reference the binary output instead (use the browse button in the add reference dialog). This removes a lot of dependency checking in the solution. It's not ideal but it does speed things up.
Upvotes: 0
Reputation: 1132
If you have multicore cpu, use /MP compiler option.
Edit: What techniques can be used to speed up C++ compilation times?
Upvotes: 2
Reputation: 73493
You can create a pre-compiled header of the files which normally wont change frequently. This can dramatically increase your compilation time.
Upvotes: 4
Reputation: 54178
Precompiled headers can be helpful if you include complex headers (STL, Boost for example) directly in a lot of files.
Make sure your build does not access the network inadvertently, or intentionally.
Upvotes: 2