开发者

When should I delete object files before compiling?

开发者 https://www.devze.com 2023-03-27 06:44 出处:网络
In compile scripts I generally see a call to always delete object files before compiling.Does this slow down the build process?Is i开发者_StackOverflow社区t really necessary with compilers that check

In compile scripts I generally see a call to always delete object files before compiling. Does this slow down the build process? Is i开发者_StackOverflow社区t really necessary with compilers that check if the object files are out of date when deciding to recompile them?


Sometimes if you revert a source file to a previous version, the .o will have a newer date that its source, and therefore won't be fed to the compiler. If you had a reason to revert the source file, you almost surely want the object rebuilt. Doing a clean build ensures you get what you think you're getting.


In some way, deleting existing object files defeats the purpose of having separate translation units in the first place. Your standard build environment should normally only rebuild those object files which are older than the corresponding source file. (You don't need to delete, you can just overwrite.)

If you have a decent revision control system, then even checking out an older version of a modified file will make the actual file on disk have a current timestamp, but indeed, if you're worried that something might be inconsistent, you can always clean up the entire build tree and start over. But as a matter of normal code writing, it would appear terribly wasteful to delete object files.

You should of course keep one set of object files for each set of build options (e.g. debug vs release). Some build environments allow you to have multiple output directories, others (like cmake) will just automatically rebuild everything if you change the global build settings, but that's something to watch out for, especially if you just add some #defines to the compiler flags in the middle of a build process.


1) Yes, and 2) no, but it's not the compiler that watches out for that, it's the build system (an IDE or well-written makefile).

0

精彩评论

暂无评论...
验证码 换一张
取 消