gpt4 book ai didi

linux - 编译两个asm文件时"nasm: error: more than one input file specified"

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:10 24 4
gpt4 key购买 nike

我正在尝试用汇编语言汇编一个由两个 asm 文件组成的小型初学者程序。我可以制作一个文件,但我想尝试调用另一个文件中的过程。
这是我的生成文件:

NAME        =   formatter

SRCS = formatter.asm clearstring.asm

OBJS = $(SRCS:.asm=.o)`

NASM = nasm
NASMFLAGS = -f elf64 -F dwarf

LD = ld

RM = rm -f

all: $(NAME)

$(NAME): $(OBJS)
$(LD) $(OBJS) -o $(NAME)

#(1):
# formatter.o: formatter.asm
# $(NASM) -o formatter.o formatter.asm $(NASMFLAGS)
# clearstring.o: clearstring.asm
# $(NASM) -o clearstring.o clearstring.asm $(NASMFLAGS)

#(2):
$(OBJS): $(SRCS)
$(NASM) -o $(OBJS) $(SRCS) $(NASMFLAGS)

当使用注释 (1) 下的代码时,一切正常,但是当我使用紧凑代码 (2) 时,make 给我:

nasm -o formatter.o clearstring.o formatter.asm clearstring.asm -f elf64 -F dwarf
nasm: error: more than one input file specified
nasm: error: more than one input file specified
type `nasm -h' for help
make: *** [formatter.o] Error 1

我知道组装步骤不对,但我做不到:

nasm -o formatter.o formatter.asm -f elf64 -F dwarf
nasm -o clearstring.o clearstring.asm -f elf64 -F dwarf

我希望我在这个网站上的第一个问题已经足够清楚了。
你能帮我么 ?

最佳答案

像这样的规则应该可以解决问题:

%.o: %.asm
$(NASM) $(NASMFLAGS) -o $@ $<

$@$<将分别扩展为目标名称和(第一个,在我们的例子中是唯一的)输入文件。

关于linux - 编译两个asm文件时"nasm: error: more than one input file specified",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21395719/

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