Linux Makefile NASM错误:指定了多个输入文件
因此,我有一个用于我正在处理的一些汇编代码的makefile,当我尝试构建代码时,我得到以下输出:Linux Makefile NASM错误:指定了多个输入文件,linux,assembly,makefile,nasm,ld,Linux,Assembly,Makefile,Nasm,Ld,因此,我有一个用于我正在处理的一些汇编代码的makefile,当我尝试构建代码时,我得到以下输出: Makefile:32: warning: overriding commands for target `obj' Makefile:29: warning: ignoring old commands for target `obj' nasm -f elf64 -g -F stabs main.asm -l spacelander .lst nasm: error: more than
Makefile:32: warning: overriding commands for target `obj'
Makefile:29: warning: ignoring old commands for target `obj'
nasm -f elf64 -g -F stabs main.asm -l spacelander .lst
nasm: error: more than one input file specified
type `nasm -h' for help
make: *** [obj] Error 1
然而,当我在谷歌上搜索时,这似乎是由于LD而不是NASM本身的链接器问题(错误中只有NASM输出,而不是LD),并且我只有一个源文件作为测试打印一个简单的文本输出。例如,OP能够执行他的代码;我的甚至不会建造
好吧,我的源文件非常好,因为在我修改它之前,代码构建和运行都很好,没有任何问题。我更改它是为了将任何.o
文件复制到obj/
目录,并将目标复制到bin/
目录
这个问题的原因可能是什么?我几乎可以肯定,这与代码无关,是由Makefile本身造成的
为了完整起见,我将粘贴Makefile和程序集源代码
来源
bits 32
section [.bss]
section [.data]
; Store three lines in the same string.
; This is just for test purposes.
Title: db "------SPACE LANDER-----", 10, \
"------SPACE LANDER-----", 10, \
"------SPACE LANDER-----", 10
Len: equ $-Title
section [.text]
global _start
_start:
mov eax, 4 ; Syswrite
mov ebx, 1 ; To stdout
mov ecx, Title ; ecx stores title to print
mov edx, Len ; store offset of len in edx
int 0x80 ; call kernel, do print
exit:
mov eax, 1 ; exit
mov ebx, 0 ; return 0
int 0x80 ; call kernel, exit safely (hopefully)
ASM := nasm
ARGS := -f
FMT := elf64
OPT := -g -F stabs
SRC := main.asm
#SRC_EXT := asm
#^unused due to suspected error causing.
OBJDIR := obj
TARGETDIR := bin
OBJ := $(addprefix $(OBJDIR)/,$(patsubst %.asm, %.o, $(wildcard *.asm)))
TARGET := spacelander
.PHONY: all clean
all: $(OBJDIR) $(TARGET)
$(OBJDIR):
mkdir $(OBJDIR)
$(OBJDIR)/%.o: $(SRC)
$(ASM) $(ARGS) $(FMT) $(OPT) $(SRC) -l $(TARGET).lst
$(TARGET): $(OBJ)
ld -o $(TARGET) $(OBJ)
clean:
@rm -f $(TARGET) $(wildcard *.o)
@rm -rf $(OBJDIR)
Makefile
bits 32
section [.bss]
section [.data]
; Store three lines in the same string.
; This is just for test purposes.
Title: db "------SPACE LANDER-----", 10, \
"------SPACE LANDER-----", 10, \
"------SPACE LANDER-----", 10
Len: equ $-Title
section [.text]
global _start
_start:
mov eax, 4 ; Syswrite
mov ebx, 1 ; To stdout
mov ecx, Title ; ecx stores title to print
mov edx, Len ; store offset of len in edx
int 0x80 ; call kernel, do print
exit:
mov eax, 1 ; exit
mov ebx, 0 ; return 0
int 0x80 ; call kernel, exit safely (hopefully)
ASM := nasm
ARGS := -f
FMT := elf64
OPT := -g -F stabs
SRC := main.asm
#SRC_EXT := asm
#^unused due to suspected error causing.
OBJDIR := obj
TARGETDIR := bin
OBJ := $(addprefix $(OBJDIR)/,$(patsubst %.asm, %.o, $(wildcard *.asm)))
TARGET := spacelander
.PHONY: all clean
all: $(OBJDIR) $(TARGET)
$(OBJDIR):
mkdir $(OBJDIR)
$(OBJDIR)/%.o: $(SRC)
$(ASM) $(ARGS) $(FMT) $(OPT) $(SRC) -l $(TARGET).lst
$(TARGET): $(OBJ)
ld -o $(TARGET) $(OBJ)
clean:
@rm -f $(TARGET) $(wildcard *.o)
@rm -rf $(OBJDIR)
可能是由于此命令中有额外的空格:
nasm -f elf64 -g -F stabs main.asm -l spacelander .lst
因为在$(TARGET)
的末尾有多余的空格,因为在这一行的末尾有多余的空格:
TARGET := spacelander
尝试删除那些多余的空间 在
OBJDIR:=obj
的末尾还有一个额外的空间,这会导致警告消息,并且即使nasm
命令成功,也会扰乱构建的其余部分。