Make: $(通配符) 保持目录打开

发布于 2024-07-07 11:16:35 字数 422 浏览 5 评论 0原文

因此,GNU Make 的 $(wildcard) 函数在 Windows 上保持目录打开似乎存在这个问题。 请参阅(unasnwered)帖子“make 保持目录打开 ”。 谷歌没有提供有关该主题的太多信息。

简而言之:Makefile 在某些时候使用 $(wildcard) 函数,并保持目录打开,这通常会阻止“make clean”规则正确执行其工作。 第二次重新运行“make clean”通常可以解决问题。

我在标准 DOS-Box 下使用 GNU Make 版本 3.81。 上面链接的帖子的作者正在使用 Cygwin。

有没有人找到解决这个问题的方法?

So there seems to be this problem with GNU Make's $(wildcard) function keeping a directory open on Windows. See (unasnwered) post "make is holding a directory open". Google does not provide much information on the topic.

In short: the Makefile uses the $(wildcard) function at some point, and keeps a directory open, which typically prevents the "make clean" rule to do its work correctly. Re-running "make clean" a second time usually solves it.

I'm using GNU Make version 3.81 under a standard DOS-Box. The author of the post linked to above is using Cygwin.

Has anyone found a fix for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

·深蓝 2024-07-14 11:16:35

听起来像是文件描述符泄漏,好吧——对于 UNIX 上生命周期非常短的进程(如 make)来说无害,但在 Windows 上却是一个正确的 PITA。

由于据称这是 make 中的一个错误,而不是其使用问题,因此应首先通过验证它在最新上游版本上从源代码构建时是否仍然存在来解决,然后通过 向 GNU make 项目(或与您有适当支持合同的任何分销商)提交错误报告,或者深入研究源头并尝试自行修复。

尝试在 Linux 上重现并没有什么坏处——在这里检查文件描述符泄漏要容易得多,因为人们可以只查看 /proc/self/fd (或者,对于 make 的子项) , /proc/$PPID/fd) 对于不属于的东西。

Sounds like a file descriptor leak, all right -- harmless for very-short-lived processes (like make) on UNIX, but a right PITA on Windows.

As this is allegedly a bug in make, as opposed to a problem with its usage, it should be addressed first by validating that it still exists when built from source on the newest upstream version, and then by filing a bug report with the GNU make project (or with any distributor with whom you have an appropriate support contract), or diving into the source and attempting to fix it yourself.

It wouldn't hurt to try to reproduce on Linux -- checking for file descriptor leaks are much easier here, as one can just look at /proc/self/fd (or, for a child of make, /proc/$PPID/fd) for things that don't belong.

断爱 2024-07-14 11:16:35

我确实找到了解决该问题的解决方法,这至少让我可以安心工作。

问题在于 $(wildcard) 函数用于收集源文件。 然而,我的干净规则只删除一个目录 - 不需要收集。 所以我基本上把 Makefile 中需要收集源文件的部分放在条件语句中:

# The clean rule is always parsed
clean:
    rm -rf $(OUTPUT_DIRECTORY)

# The compile rule is only interpreted if we did not invoke 'make clean'. We
# can test the value of $(MAKECMDGOALS) for that:
ifeq ($(filter $(MAKECMDGOALS),clean),)

SOURCE_FILES := $(wildcard ...)

compile:
    g++ $(SOURCE_FILES) ...

endif

I did find a workaround for the problem, which at least lets me work in peace.

The problem was that the $(wildcard) function was used to collect the sources files. My clean rule, however, only deletes a directory - no need for the collecting to take please. So I basically put the part of the Makefile that needs to collect the sources files in a conditional statement:

# The clean rule is always parsed
clean:
    rm -rf $(OUTPUT_DIRECTORY)

# The compile rule is only interpreted if we did not invoke 'make clean'. We
# can test the value of $(MAKECMDGOALS) for that:
ifeq ($(filter $(MAKECMDGOALS),clean),)

SOURCE_FILES := $(wildcard ...)

compile:
    g++ $(SOURCE_FILES) ...

endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文