Slow compilation with many files

J.C. Pizarro jcpiza@gmail.com
Sun Apr 20 02:53:00 GMT 2008


Zed <perrose@kth.se> wrote:
> I've tried to make my c++ source files small in my current project. Compiling
> my approx. 20 files takes very long time. I created a new source file that
> just includes all my original ones with #include statements, and compiled
> it. This method was much quicker. Compiling all files included in one takes
> approx. double the time compared to that of compiling just one of the small
> source files. So If I make a change to some header that is included by many
> of the source files, the last described method that includes the files to
> one is much faster.
>
> It seems there is a lot of compilation time overhead if the code is compiled
> in many small parts - this is without taking linking into account. Is there
> any settings or some trick that can reduce this overhead, except my ugly
> inclusion method?
>
> This is the command executed per source file, created by autoconf:
>
> g++ -DHAVE_CONFIG_H -I. -I.. -DPACKAGE_LOCALE_DIR=\""/usr/local//locale"\"
> -DPACKAGE_SRC_DIR=\""."\" -DPACKAGE_DATA_DIR=\""/usr/local/share"\"
> -I/usr/include/opencv   -pthread -I/usr/include/glib-2.0
> -I/usr/lib/glib-2.0/include   -I/usr/include/gtk-2.0
> -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo
> -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
> -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/pixman-1
> -I/usr/local/include/ltilib -D_GNU_SOURCE -fpic -D_DEBUG    -g -O2 -MT
> pick-vertex-manipulator.o -MD -MP -MF .deps/pick-vertex-manipulator.Tpo -c
> -o pick-vertex-manipulator.o pick-vertex-manipulator.cpp
>
> Which is essentially after removing unimportant stuff:
>
> g++ -DHAVE_CONFIG_H -D_GNU_SOURCE -fpic -D_DEBUG -g -O2 -MT
> pick-vertex-manipulator.o -MD -MP -MF .deps/pick-vertex-manipulator.Tpo -c
> -o pick-vertex-manipulator.o pick-vertex-manipulator.cpp
>
> Thank you!

I think that GCC lacks
http://en.wikipedia.org/wiki/Memoization

With Memoization and gcc-kernel daemon, it can compile faster bigger apps.



More information about the Gcc-help mailing list