Makefile 始终认为项目是最新的 - 但文件甚至不存在

发布于 2024-10-07 19:08:04 字数 976 浏览 1 评论 0原文

我有以下 makefile: 我的

CCC = g++
CCFLAGS = -ansi

driver: driver.o graph.o
        $(CCC) -o driver driver.o graph.o

graph.o: graph.h
driver.o: graph.h

adjl:
        rm -f graph.h graph.cc
        ln -s adjl/graph.cc .
        ln -s adjl/graph.h .
        touch graph.cc graph.h
adjm:
        rm -f graph.h graph.cc
        ln -s adjm/graph.cc .
        ln -s adjm/graph.h .
        touch graph.cc graph.h

clean:
        rm -f *.o
real_clean: clean
        rm -f graph.cc graph.h
        rm -f driver

想法是,我尝试根据我要使用的实现来链接两个不同的 .cc/.h 文件。如果我进行 real_clean,则 .cc/.h 文件都不存在,文件夹中只有 driver.cc 文件和 makefile。如果我调用 make,它会说它们是最新的。即使我编辑 adjl/adjm 中的文件以使其成为“较新”版本,也会发生这种情况。

 [95]% ls
adjl/  adjm/  driver.cc  makefile
 [96]% make adjl
make: `adjl' is up to date.
 [97]% make adjm
make: `adjm' is up to date.

我从我完成的另一个项目中获取了模板 makefile,它们的编写方式相同,但我可以重复执行相同的命令,而不会出现“最新”问题。

我已经用谷歌搜索过,但没有发现与我类似的问题(它们通常似乎涉及在制作前不进行清洁的用户)。

感谢任何人的阅读。

I have the following makefile:

CCC = g++
CCFLAGS = -ansi

driver: driver.o graph.o
        $(CCC) -o driver driver.o graph.o

graph.o: graph.h
driver.o: graph.h

adjl:
        rm -f graph.h graph.cc
        ln -s adjl/graph.cc .
        ln -s adjl/graph.h .
        touch graph.cc graph.h
adjm:
        rm -f graph.h graph.cc
        ln -s adjm/graph.cc .
        ln -s adjm/graph.h .
        touch graph.cc graph.h

clean:
        rm -f *.o
real_clean: clean
        rm -f graph.cc graph.h
        rm -f driver

The idea is that I am trying to link two different .cc/.h files depending on which implementation I want to use. If I make real_clean, none of the .cc/.h files exist, I merely have a driver.cc file and the makefile in the folder. If I call make, it says they are up to date. This happens even if I edit the files in adjl/adjm to make them "newer" versions.

 [95]% ls
adjl/  adjm/  driver.cc  makefile
 [96]% make adjl
make: `adjl' is up to date.
 [97]% make adjm
make: `adjm' is up to date.

I took the template makefile from another project I had done, and they are written the same way but I can repeatedly make the same commands with no "up to date" issues.

I have googled but have not found a problem similar to mine (they generally seem to involve users who aren't cleaning before making).

Thanks to anyone for reading.

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

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

发布评论

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

评论(3

若无相欠,怎会相见 2024-10-14 19:08:04

问题在于您的目录名称与 Makefile 中的目标名称相同。

当您发出 make adjl 时,make 检查它找到的文件 adjl并且什么也不做。
将目标重命名为其他名称,然后重试。

The problem is that you have directory named the same as your targets in Makefile.

When you issue make adjl make checks for file adjl which it finds and does nothing.
Rename targets to something else and try again.

心房敞 2024-10-14 19:08:04

adjladjm 目标是真实目标。由于它们没有依赖项,并且文件存在(列表中的 2 个目录),因此 make 不会执行任何操作(因为它们就在附近)。

但是,您想要的是将 adjladjm 指定为虚假目标(以便在您指定它们时执行命令)。为此,

.PHONY: adjl adjm

请阅读 http://www.gnu.org/ software/automake/manual/make/Phony-Targets.html 了解更多信息。

编辑

事实上,real_cleanclean 规则可能也应该是假的。

The adjl and adjm targets are real targets. Since they have no dependencies, and the files are present (the 2 directories in your listing), make doesn't do anything (because they are around).

However, what you want is to specify adjl and adjm as phony targets (so that the commands are executed when you specify them). To do so,

.PHONY: adjl adjm

Read http://www.gnu.org/software/automake/manual/make/Phony-Targets.html for more information.

EDIT

In fact, the real_clean and clean rules should probably also be made phony.

亽野灬性zι浪 2024-10-14 19:08:04

您的目录与您的目标同名。

由于您的目标不依赖于任何东西,因此它们将始终被认为是最新的。

当指定未链接到磁盘上文件的目标时,您需要使用特殊目标 .PHONY

.PHONY: adjl adjm

您还应该对 clean 和 real_clean 目标执行相同的操作 - 否则它们'如果有人创建一个名为“clean”的文件,就会中断。

Your have directories with the same name as your targets.

Since your targets don't depend on anything, they'll always be considered up to date.

When specifying a target that isn't linked to a file on disk, you need to use the special target .PHONY:

.PHONY: adjl adjm

You should also do the same for your clean and real_clean targets as well - otherwise they'll break if someone creates a file called "clean".

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