【问题标题】:Unable to compile a simple application无法编译简单的应用程序
【发布时间】:2017-05-19 00:25:13
【问题描述】:

我正在尝试为 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

【问题讨论】:

标签: assembly nasm


【解决方案1】:

在 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

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2020-11-13
    相关资源
    最近更新 更多