I have a c++ program which has many many functions and I have different .cpp files for each of the function. From the main program, I only supply a few parameters and just call the functions. However, the compilation of the full thing takes a lot of time. For each compilation I only change a few parameters in the main program and leave all the functions as it is.
Is there anyway to speed up the compilation.?
I have a c++ program which has many many functions and I have different
Share
You are recompiling unnecessary code. Usually IDEs handle this automatically. Otherwise, it depends on how you compile your code. For example lines like this:
or
are terribly slow, because on every compilation, you recompile everything.
If you are writing Makefiles, you should carefully write it to avoid recompilation. For example:
In the above example, changing
c.cppcauses compilation ofc.cppand linking of the program. Changinga.hcauses compilation ofa.oandb.oand linking of the program. That is, on each build, you compile the minimum number of files possible to make the program up-to-date.Side note: be careful when writing Makefiles. If you miss a dependency, you will may not compile enough files and you may end up getting hard-to-spot segmentation faults (at best). Take a look also at the manual of
gccfor-M*options where you can usegccitself to generate the dependencies and thenincludethe generated output in theMakefile.