linux - 生成文件 NASM 错误 : more than one input file specified

标签 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 one input file specified
type `nasm -h' for help
make: *** [obj] Error 1

然而,当我用谷歌搜索时,这似乎是由于 LD 而不是 NASM 本身的链接器问题(错误中只有 NASM 输出而不是 LD),而且我只有一个源文件,它打印一个简单的文本输出为一个测试。在 this例如,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)

最佳答案

可能是由于此命令中的额外空格:

nasm -f elf64 -g -F stabs main.asm -l spacelander   .lst

因为你在 $(TARGET) 的末尾有额外的空格,因为你在这一行的末尾有额外的空格:

TARGET := spacelander

尝试删除那些多余的空格。

关于linux - 生成文件 NASM 错误 : more than one input file specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12634172/

相关文章:

linux - 我可以在 Ubuntu 上开发 Microsoft Dynamics 365 吗?

c - 文件访问中文本模式和二进制模式有什么区别吗?

assembly - MOV 到宏参数指定的寄存器中

linux - 从 ELF 中删除汇编指令

python - 显式链接本地共享对象库

在 Raspbian 中创建 Makefile

c - 如何在cooja中创建makefile?

Linux x86 CPU指令布局困惑

c - 对于 C 开发人员,Clang 版本 2.8 和 3.1 之间有什么实际区别?

performance - 在没有优化的情况下添加冗余分配可以加快代码的速度