【发布时间】: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(命名为Makefile或makefile)和.c 文件应该在那里。 -
另外,您使用的是 GNU make 吗? (运行
make -v找出答案)。 -
是的,所有文件都在同一个目录中,我使用的是 GNU Make 4.1。 i.imgur.com/r5EnwHj.png