【问题标题】:Makefile produces error "No rule to make target"Makefile 产生错误“没有规则来制作目标”
【发布时间】:2016-07-07 19:38:41
【问题描述】:

我已尝试使用其他两个最相关的主题来解决此问题: Makefile error: No rule to make target Makefile: No rule to make target. Stop

但似乎都没有解决我的问题。

我不确定我的代码哪里出错了,因为我的讲师验证了代码在他的一端是否有效。

我的makefile的代码是:

TARGET  = demo
FILES   = test.c
OBJS    = $(FILES:.c=.o)
ASMS    = $(FILES:.c=.s)

all:    $(TARGET)

$(TARGET):  $(OBJS)
    gcc -o $@ $^

%.o:    %.c
    gcc -c $< -o $@

%.s:    %.c
    gcc -S -masm=intel $< -o $@

asm:    $(ASMS)

run:    $(TARGET)
    ./$(TARGET)

clean:
    rm -f $(TARGET) $(OBJS) $(ASMS)

但是,当我尝试执行“make run”时,它会产生结果

make: *** No rule to make target 'run'. Stop.

在这里看到image

我尝试编译的程序的实际代码只有 4 行。我不认为这是问题的原因

#include <stdio.h>
char *msg = "Exam Lab 1";

int main(int argc, char *argv[]) {
    printf("%s\n", msg);
}

这是我正在运行的目录的内容 make 来自:

【问题讨论】:

  • 确保每个配方的缩进行只使用制表符,而不是空格。
  • 感谢您的提醒。完全忘记了makefile依赖于选项卡,但是我仍然遇到了问题。 i.imgur.com/wioJc37.png
  • 您运行make 的目录的内容是什么? makefile(命名为Makefilemakefile)和.c 文件应该在那里。
  • 另外,您使用的是 GNU make 吗? (运行make -v 找出答案)。
  • 是的,所有文件都在同一个目录中,我使用的是 GNU Make 4.1。 i.imgur.com/r5EnwHj.png

标签: c linux makefile


【解决方案1】:

您的 makefile 没有正确的名称。

默认情况下,make 会查找名为 makefileMakefile 的文件。你的名字是Makefile.txt,所以make 找不到。

要么将名称更改为makefileMakefile,要么使用-f 选项指定makefile 名称,例如。 make -f Makefile.txt.

【讨论】:

  • 你知道,我是个智障。谢谢这个修复它,我猜我太习惯 Windows了。
【解决方案2】:

从您提供的图像中可以清楚地看出您已将文件命名为Makefile.txt。正如@dbush 所说,生成文件必须 命名为Makefilemakefile。这些是默认情况下唯一查找的文件名。

要么这样,要么你必须运行make -f Makefile.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    相关资源
    最近更新 更多