C语言 “make clean”导致“没有规则可以使目标‘clean’”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4182118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"make clean" results in "No rule to make target `clean'"
提问by jasonbogd
I am running Ubuntu 10.04. Whenever I run make clean, I get this:
我正在运行 Ubuntu 10.04。每当我跑步时make clean,我都会得到这个:
make: *** No rule to make target `clean'. Stop.
make: *** 没有使目标“干净”的规则。停止。
Here is my makefile:
这是我的生成文件:
CC = gcc
CFLAGS = -g -pedantic -O0 -std=gnu99 -m32 -Wall
PROGRAMS = digitreversal
all : $(PROGRAMS)
digitreversal : digitreversal.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: clean
clean:
@rm -f $(PROGRAMS) *.o core
Any ideas why its not working?
任何想法为什么它不起作用?
EDIT: It seems like doing:
编辑:这似乎是在做:
make -f Makefile.txt clean
works. Now: is there any setting to change so I don't have to do the -f Makefile.txtevery time?
作品。现在:是否有任何设置可以更改,以便我不必-f Makefile.txt每次都这样做?
采纳答案by Siddique
It seems your makefile's name is not 'Makefile' or 'makefile'. In case it is different say 'abc' try running 'make -f abc clean'
似乎您的 makefile 的名称不是“Makefile”或“makefile”。如果情况不同,请说“abc”尝试运行“make -f abc clean”
回答by Navaneetha Kandethodi
I suppose you have figured it out by now. The answer is hidden in your first mail itself.
我想你现在已经想通了。答案隐藏在您的第一封邮件中。
The makecommand by default looks for makefile, Makefile, and GNUMakefileas the input file and you are having Makefile.txtin your folder. Just remove the file extension (.txt) and it should work.
该make命令默认查找makefile, Makefile, 和GNUMakefile作为输入文件,并且您Makefile.txt在文件夹中。只需删除文件扩展名 ( .txt) 就可以了。
回答by Spaceghost
Check that the file is called GNUMakefile, makefile or Makefile.
检查该文件是否称为 GNUMakefile、makefile 或 Makefile。
If it is called anything else (and you don't want to rename it) then try:
如果它被称为其他任何东西(并且您不想重命名它),请尝试:
make -f othermakefilename clean
make -f othermakefilename clean
回答by Michael Foukarakis
You have fallen victim to the most common of errors in Makefiles. You always need to put a Tab at the beginning of each command. You've put spaces before the $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)and @rm -f $(PROGRAMS) *.o corelines. If you replace them with a Tab, you'll be fine.
您已成为 Makefile 中最常见错误的受害者。您总是需要在每个命令的开头放置一个 Tab。您在$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)和@rm -f $(PROGRAMS) *.o core行之前放置了空格。如果你用 Tab 替换它们,你会没事的。
However, this error doesn't lead to a "No rule to make target ..." error. That probably means your issue lies beyond your Makefile. Have you checked this is the correct Makefile, as in the one you want to be specifying your commands? Try explicitly passing it as a parameter to make, make -f Makefileand let us know what happens.
但是,此错误不会导致“No rule to make target ...”错误。这可能意味着您的问题超出了您的 Makefile。您是否检查过这是正确的 Makefile,就像您要指定的命令一样?尝试将其作为参数显式传递给 make,make -f Makefile并让我们知道会发生什么。
回答by Simone
This works for me. Are you sure you're indenting with tabs?
这对我有用。您确定要使用制表符缩进吗?
CC = gcc
CFLAGS = -g -pedantic -O0 -std=gnu99 -m32 -Wall
PROGRAMS = digitreversal
all : $(PROGRAMS)
digitreversal : digitreversal.o
[tab]$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: clean
clean:
[tab]@rm -f $(PROGRAMS) *.o core

