这看起来可能是由nasm产生的和ld试图做的内容之间的简单的不匹配:
i386 architecture of input file 'hello.o' is incompatible with i386:x86-64 output
换句话说,nasm已经生成了一个32位的对象文件hello.o,ld想要这样做,并且做一个64位的可执行文件.
nasm -hf命令应该给你可用的输出格式:
valid output formats for -f are (`*' denotes default):
* bin flat-form binary files (e.g. DOS .COM, .SYS)
ith Intel hex
srec Motorola S-records
aout Linux a.out object files
aoutb NetBSD/FreeBSD a.out object files
coff COFF (i386) object files (e.g. DJGPP for DOS)
elf32 ELF32 (i386) object files (e.g. Linux)
elf ELF (short name for ELF32)
elf64 ELF64 (x86_64) object files (e.g. Linux)
as86 Linux as86 (bin86 version 0.3) object files
obj MS-DOS 16-bit/32-bit OMF object files
win32 Microsoft Win32 (i386) object files
win64 Microsoft Win64 (x86-64) object files
rdf Relocatable Dynamic Object File Format v2.0
ieee IEEE-695 (LADsoft variant) object file format
macho32 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
macho MACHO (short name for MACHO32)
macho64 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
dbg Trace of all info passed to output stage
我看到您链接的教程要求您运行:
nasm -f elf hello.asm
尝试使用:
nasm -f elf64 hello.asm
相反,您可能会发现ld停止抱怨输入文件.