Why / when do I need a β€œclean” goal?

Sometimes it seems that a new executable file is not created, although I need it, but I do not understand why. For example, when I modify the Makefile, but there is already an executable, and when I execute make, it does not create an updated executable.

Isn't that the whole purpose of Make files, so I no longer need to worry about that?

+6
source share
3 answers

From GNU make documentation

Re-compilation should be performed if the source file or any of the header files called dependent are later than the object file, or if the object file does not exist.

It does not change your Makefile, which runs it.

make clean deletes all object files that were created at the same time. As a rule, there is no need to partially recompile, i.e. Only recompile the files that you changed, and finally associate the newly created object files with existing ones. However, if you want to be completely safe, you must run make clean before running make .

An example where saving old object files (i.e. never cleanup) can be a problem: suppose you have an existing object file that must be associated with version 1.0 of some library. Now you are updating your computer, and version 1.1 will be installed on it, where some function is incompatible with function 1.0. But since your object file was compiled in anticipation of the previous version, the linking process will ultimately fail.

+6
source

Well, that’s a very broad question. Typically, you can write a makefile that will track all dependencies (including its own modification time). However, it is not trivial, and errors can be scanned into your makefile in the same way as for any other code. Therefore, it is sometimes easier to clear everything and rebuild, suspecting that something was not built correctly.

There are many other building tools , such as scons , which can be more reliable / automatic than makefile.

+1
source

Analyze the dependencies defined in your Makefiles and plot the dependencies.

If he discovers that any of the requirements necessary to change the output (binary files), he rebuilds - or at least the changed part.

So, if your dependency includes Make files - it probably shouldn't - make will update the binary after changing the Makefile.

Living with Makefiles is not always easier, but it can help you anyway.

+1
source

Source: https://habr.com/ru/post/892442/


All Articles