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

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

本文介绍了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:为什么我的目标命令没有执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:02