makefiles - 干净的目标
谁能告诉我如何执行 makefile 中写入的 clean 目标。 这是我的代码
jamm : hello.o ghola.o
gcc $^ -o $@
%.o : %.c
gcc -c S<
clean :
rm *.c
,我有一些问题。如何使用 clean 作为目标来清理所有这些 c 文件。我们给出命令 make -f file1(假设文件名是 file1),它会将目标视为 jamm 并执行,但它不会执行 clean 目标。如果在命令行中我说 make clean 它说没有这样的文件或目录,我是无法理解这个概念,任何人都可以告诉我当我在 make 文件中写入时如何执行这些干净的操作。请大家帮忙
can anyone tell me how to execute the clean target which is written in the makefile.
here is my code
jamm : hello.o ghola.o
gcc $^ -o $@
%.o : %.c
gcc -c S<
clean :
rm *.c
i have some questions.how to clean all those c files using the clean as target. we give the command make -f file1(say filename is file1) and it sees the target as jamm and execute but it wont execute the clean target.If in the command line i say make clean it says no such file or directory i'm unable to get this concept can anyone please tell me how to execute these clean when i have written in my make file.please guyss
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您的目录中是否有名为“clean”的文件。
您的
make
调用可能认为它必须以某种方式生成一个“干净”的文件。要解决此问题,请尝试在干净目标之前添加 .PHONY指标:
顺便说一下:你的干净目标看起来很糟糕:你不应该删除.o文件而不是.c吗???
Check in your directory if you have a file named "clean".
It might be that your
make
call thinks it must generate a "clean" file somehow.To fix this, try to add just before your clean target a .PHONY indicator:
BY THE WAY: YOUR CLEAN TARGET LOOKS BAD: shouldn't you delete the .o files instead of the .c ????
在我的一个 makefile 中,
clean
目标如下所示:请注意,包含可执行语句的行以制表符开头。
其他一些事情:
rm
您的.c
文件。这些是您的源文件,您可能会丢失对它们进行编码的所有工作。.o
)和可执行文件(在我的示例中为$(PROGS)
,实际上是包含对象名称的任何变量可执行文件)文件和预编译头文件(.gch
),因此您可以从头开始重新制作。clean
)应列为.PHONY
的先决条件。这让 make 知道即使有一个名为clean
的文件,它也应该运行该命令。要执行特定目标(例如
clean
),只需输入但请确保:
Makefile
或makefile
。如果您使用的是 GNU make,您也可以将其命名为GNUmakefile
In one of my makefiles, the
clean
target looks like this:Note that the line with the executable statement begins with a tab.
Some other things:
rm
your.c
files. Those are your source files, and you could lose all your work coding them..o
in my example) and executable ($(PROGS)
in my example, really any variable that contains the names of the executables) files, and precompiled headers (.gch
), so you can remake from a clean slate.clean
, should be listed as prerequisites of.PHONY
. This lets make know that even if there is a file calledclean
, it should run the command anyway.To execute a particular target (
clean
for example), just enterbut make sure that:
Makefile
ormakefile
. If you are using GNU make, you can also call itGNUmakefile