[SOLVED] Project compilation very very slow with boost
-
Hi,
I am using Qt 4.8.1 along with boost libraries (especially boost::asio), on Windows 7 with Visual Studio 2010. It takes little more time to compile boost based programs, but it is acceptable. But when I mix Qt and boost the "moc" process as well as the compilation of each file (the files which are independent of boost also)takes lot of time. Does anybody have experienced this? What could be the reason? How can it be solved?
The compilation time really affects our productivity.
Thanks,
Lloyd -
Try running one of those slow files through the C preprocessor and check how big the output is. My guess is that you are dragging in (almost) all of Qt and boost at the same time. Having a couple of lines turn into a >100k line monster does happen and the compiler will have to munch through all that data.
Try to reduce the amount of includes, use forward declarations whenever possible, etc. You might also be able to use precompiled headers to speed this up.
-
Try especially to avoid including Boost headers in your header files, preferring to include them only in the implementation files. The private implementation method can help here. If you must include Boost headers in other header files make sure you use the forward declaration headers (i.e. *_fwd.h) if at all possible, and the bare minimum specific Boost includes otherwise.
Asio is header-only, so there is a quite a lot of implementation code to build for every single file that includes it. You could also try using the "Optional separate compilation":http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/using.html mechanism.
-
Thanks a lot. As a first attempt I went with precompiled headers and it has improved very much. To improve it further I shall try including the "*_fwd.h" headers.
-
You should always try to include as less as possible in headers.
A common way is to use forward declarations for all things that are needed and only include the headers for member variables, if they are no pointers. This speeds up building a lot. Pre compiled headers also have a big disadvantage:You perhaps need to include them in the header (or it is not usable in cpp files if they do not want to include the pre compiled header or come from a different binary artifact). And if you add a header, you have to recompile the whole thing and not only one cpp.
-
Thats an important point. As a quick fix I opted the precompiled header option. I will be moving to forward headers as soon as possible. I am using only very minimal headers in my header files.
-
Here we are using "Incredibuild":http://www.incredibuild.com , which distribute the build process all over our machines. Builds that went on for 3 hours are now taking less than 20 minutes. You should definitely take a look and see if it suites you!
-
Which boost-libs are you using? If you're using spirit and do some parsing it will take a long time beacause of meta-template-programming,
-
Solved? What was the problem? Please tell. So everybody can benefit from your experience.