为什么/什么时候我需要“干净”?目标?
有时似乎没有构建新的可执行文件,即使我需要一个,但我不明白为什么。例如,当我更改 Makefile,但已经有一个可执行文件时,当我执行“make”时,它不会创建更新的可执行文件。
Makefiles 的全部目的不就是让我不再需要担心这些事情吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 GNU make 文档
触发它的不是更改您的 Makefile。
make clean
删除同时创建的所有目标文件。 通常,部分重新编译没什么大不了的,即仅重新编译更改的文件,最后将新创建的目标文件与预先存在的目标文件链接起来。不过,如果您想绝对安全,则应在再次运行make
之前运行make clean
。保留旧目标文件(即从不运行 make clean)可能会成为一个问题的示例:假设您有一个已经存在的目标文件,该文件旨在与某个库的 1.0 版本链接。现在您更新您的计算机,这将在其上安装版本 1.1,其中某些功能与功能 1.0 不兼容。但由于您的目标文件是在预期先前版本的情况下编译的,因此链接过程最终将失败。
From the GNU make documentation
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 runmake clean
before runningmake
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.
嗯,这是一个非常广泛的问题。一般来说,您可以编写一个 makefile 来跟踪所有依赖项(包括它自己的修改时间)。然而,这并不是一件小事,错误可能会像任何其他代码一样爬到您的 makefile 中。因此,有时,当怀疑某些内容未正确构建时,清理所有内容并重建会更容易。
还有许多其他构建工具,例如scons 可能比 makefile 更强大/自动。
Well, it's a very broad question. Generally, you can write a makefile which will track all the dependencies (including it's own modification time). However it's non trivial and bugs can crawl to your makefile the same as to any other code. So, sometimes it's easier to clean everything and rebuild when suspecting that something was not built correctly.
There are many other build tools, such as scons which might be more robust/automatic than makefile.
分析 Makefile 中定义的依赖关系并从中构建依赖关系图。
如果它检测到输出(二进制文件)所需的任何先决条件发生更改,则会重建 - 或者至少重建已更改的部分。
因此,如果您的依赖项包含 Makefile(可能不应该),一旦您更改 Makefile,make 就会更新二进制文件。
使用 Makefile 的生活并不总是更容易,但无论如何它可以为您提供很大帮助。
Make analyzies the depedencies defined in your Makefiles and build a dependency graph out of that.
If it detects that any of the prequisites need by the output (binaries) changes it is rebuild - or at least the part that has changed.
So, if your dependency includes the Makefiles - it probably shouldn't - make would update the binary once you change the Makefile.
Life with Makefiles doesn't always easier but it can help you very much anyway.