Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why/when do I need a 'clean' target?

Sometimes it seems like not a new executable is built, even though I need one, but I don't understand why. For example, when I change a Makefile, but there is already an executable, and when I execute 'make' it doesn't create an updated executable.

Isn't the whole purpose of Makefiles so that I don't need to worry about that stuff anymore?

like image 562
Blub Avatar asked Jul 10 '11 16:07

Blub


1 Answers

From the GNU make documentation

The recompilation must be done if the source file, or any of the header files named as dependencies, is more recent than the object file, or if the object file does not exist.

It's not changing your Makefile that triggers it.

make clean removes all the object files that had been created in the meantime. Normally, it's no big deal to partially recompile, i.e. only to recompile the files you changed and finally link the newly created object files with the pre-existing ones. Still, if you want to be absolutely safe, you should run make clean before running make again.

An example where keeping old object files (i.e. never running make clean) may become a problem: Suppose you have an already existing object file that is meant to be linked against version 1.0 of some library. Now you update your machine and this will install version 1.1 on it, where some function is incompatible to the of function 1.0. But since your object file was compiled expecting the prior version the linking process will ultimately fail.

like image 62
emboss Avatar answered Oct 12 '22 22:10

emboss