2017-01-04 14 views
0

我试图编译此为Linux拱64,我想:无法编译一个简单的应用

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 
+4

[使用64位平台LD生成32位可执行文件(的可能的复制http://stackoverflow.com/questions/30184929/use-ld-on -64位平台生成32位可执行文件) –

+0

您正在告诉链接器创建一个64位二进制文​​件,但汇编代码是为32位组装的。将'-m elf_i386'标志传递给你的链接器。 –

+0

也在这里重复http://stackoverflow.com/questions/19200333/architecture-of-i386-input-file-is-in-comcomment-with-i386x86-64 –

回答

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