My project currently takes 16 minutes to compile.
Is there anyway that I can reduce the compilation time significantly?

Optimize all your functions and maybe use as much dynamically created variables etc as possible. Sorry dont know other then maybe upgrade your computer hardware(maybe over clock your cpu).

Ok -- First off a little help with how big / and how much cpu you have available [and memory] would have helped. OS and compiler would be useful information.

however, if you get to 16minutes on anything remotely modern and anything remotely
under 250,000 lines of total code + comments you are likely making serious errors.

I will assume that your are using a Makefile with reasonable dependencies etc, if you are compiling your whole project each time, please please read about Makefile

First off: disentangle your include list. The biggest problem with c++ projects is that everyone seems to want to put #include's in .h files. Don't do it. It is MUCH better to see the list in the c++ file. Even if it is long -- It is easier to follow if you are looking for what is dependent and it is easier to see what has become bloated.

Second: Move stuff out of the .h files. If the code for a method is in the .h file (i.e. the class definition) it is going to be compiled each time the .h file is included in a file. That means template classes as well.

Third: Use explicit template instantiation. This is obviously not going to work if the product is a library, but will work if the product is an application since you have final control. That cuts a HUGE chunk off the compile time using g++.

Four: Now have a look and start putting pre-declarations e.g. class A; and removing the actual includes. For example you don't need to include a full class definition for any pointer or reference which is only part of a .h definition [You do if you use the pointer/reference in the definition part of a class.]

Five: If you are using visual C++ : Sorry it is slow. Use something else. If you are using cygwin/g++ that is REALLY slow. It it is a Qt project, then you may have issues with moc being a little slow. I am guessing as to your likely problem.

If your project contains lots of *.c and/or *.cpp files with lots of includes that are common among all of them then using precompiled headers will help speed up the compile process. How to do that, if it can be done at all, will depend on the compiler you are using.

But 16 minutes isn't really so bad -- in 1985 I used to start a program compiling then go read a book or do something else for two hours.

This article has been dead for over six months. Start a new discussion instead.