gpt4 book ai didi

assembly - 为什么我没有指定 make add rm 命令?

转载 作者:行者123 更新时间:2023-12-01 00:15:09 25 4
gpt4 key购买 nike

关闭。这个问题需要debugging details .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




我刚刚创建了一个通用的 makefile 来编译和链接汇编程序文件:

AS=nasm
ASFLAGS=-g -f elf64
LDFLAGS=-m elf_x86_64 -static
BINARIES=print_args64

all: $(BINARIES)

%: %.o
$(LD) $(LDFLAGS) -o $@ $<

%.o: %.asm
$(AS) $(ASFLAGS) -o $@ $<

clean:
$(RM) $(BINARIES) $(wildcard *.o)

运行 make all我希望以下内容:
nasm -g -f elf64 -o print_args64.o print_args64.asm
ld -m elf_x86_64 -static -o print_args64 print_args64.o

但它实际上增加了一个 rm对象的命令如下:
 rm print_args64.o

这是从哪里来的,我该如何避免?

我找不到这方面的任何文档。

问候, bvolkmer

最佳答案

make删除它是因为它是一个中间文件而不是因为 clean你可能会想到的目标。见 chapter 10.4 Chains of Implicit Rules in the manual .相关引述:

The second difference is that if make does create b in order to update something else, it deletes b later on after it is no longer needed. Therefore, an intermediate file which did not exist before make also does not exist after make. make reports the deletion to you by printing a ‘rm -f’ command showing which file it is deleting.





You can prevent automatic deletion of an intermediate file by marking it as a secondary file. To do this, list it as a prerequisite of the special target .SECONDARY. When a file is secondary, make will not create the file merely because it does not already exist, but make does not automatically delete the file. Marking a file as secondary also marks it as intermediate.

You can list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite of the special target .PRECIOUS to preserve intermediate files made by implicit rules whose target patterns match that file’s name



另请注意,您可以询问 make使用 -d 获取有关它正在做什么的额外信息开关,打印如下内容:
Successfully remade target file `all'.
Removing intermediate files...
rm print_args64.o

关于assembly - 为什么我没有指定 make add rm 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53353462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com