无法编译简单的应用程序

时间:2017-01-04 16:14:55

标签: assembly nasm

我正在尝试为Linux Arch x64编译这个,我正在尝试:

section .text
global _start
_start:
        mov edx, len
        mov ecx, msg
        mov ebx, 1
        mov eax, 4
        int 0x80

        mov eax, 1
        int 0x80

section .data
msg db 'hi123', 0xa
len equ $ - msg

$ nasm -f elf test1.asm
$ ld -s -o test1 test1.o

但是错误:

/usr/bin/ld: i386 architecture of input file `test1.o' is incompatible with i386:x86-64 output

1 个答案:

答案 0 :(得分:0)

在x86_64上链接32位应用程序时,将模拟设置为elf_i386可提供正确的elf格式。因此,例如,如果使用nasm -f elf file.asm -o file.o编译汇编程序应用程序,则链接命令为ld -m elf_i386 -o exename file.o。

所以请改用

nasm -f elf test1.asm
ld -m elf_i386 -o test1 test1.o