Makefile:为什么我的目标命令没有执行?

编程入门 行业动态 更新时间:2024-10-27 10:30:51
本文介绍了Makefile:为什么我的目标命令没有执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在努力提高对make如何运行命令的理解. 我已经写了这个makefile文件:

I'm trying to improve my understanding how make runs commands. I have written this makefile:

TARGET=fmake TARGET2=test_second fmake: $(TARGET2).c foo.c\ $(TARGET).c test.h $(CC) -o $(TARGET) $(TARGET).c foo.c $(CC) -o $(TARGET2) $(TARGET2).c foo.c: echo This is foo.c clean: rm -f fmake test_second CC=$(VAR2) VAR2=gcc

运行make时,将显示以下shell命令:

And when running make, these shell commands displayed:

gcc -o fmake fmake.c foo.c gcc -o test_second test_second.c

但是我希望显示三个命令(也是目标foo.c):

But I expect that there are three commands displayed (also target foo.c):

This is foo.c gcc -o fmake fmake.c foo.c gcc -o test_second test_second.c

请解释为什么会这样.

推荐答案

在您的Makefile中,foo.c没有依赖性.只要该文件存在,相应的操作就不会运行.

In your Makefile, foo.c has no dependencies. As long as that file exists, the corresponding actions will not be run.

如果您重新运行make,也会发生相同的情况.它将尝试构建的第一件事是fmake.但是,由于所有目标的依赖关系已经存在,并且早于fmake文件,因此不会构建任何文件.与foo.c相同,只是它没有依赖性(因此,如果文件存在,它将永远不会执行操作).

It's the same thing that happens if you rerun make. The first thing it will try to build is fmake. But since all that target's dependencies already exist, and are older than the fmake file, nothing will be built. Same thing for foo.c, except that it has no dependencies (so it will never run the actions if the file exists).

更多推荐

Makefile:为什么我的目标命令没有执行?

本文发布于:2023-07-07 09:08:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1061432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   目标   Makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!