ld: i386 architecture of input file `write.o' is incompatible with i386:x86-64 output报错

当我在进行一个简单的编译一个内核的时候,在输入如下命令后

 nasm -f elf -o write.o write.S
 ld -m elf_i386 -s -o write.bin write.o

出现报错如下:

ld: i386 architecture of input file `write.o' is incompatible with i386:x86-64 output

原因是我用的ubuntu是64位的,在x86_64上编译/链接32位应用程序时,设置模拟以elf_i386提供正确的elf格式。

解决方案:将链接的语句换成下面这个

ld -m elf_i386 -s -o write.bin write.o

即可

顺便附上我的第一个用汇编写的系统调用:write函数

section .data
str_c_lib: db "c library say : hello world!",0xa
str_c_lib_len equ $-str_c_lib


section .text
global _start


_start:
	
	push str_c_lib_len
	push str_c_lib
	push 1
	call simu_write
	add esp,12

	mov eax,1
	int 0x80

simu_write:
	push ebp
	mov ebp,esp
	mov eax,4
	mov ebx,[ebp+8]
	mov ecx,[ebp+12]
	mov edx,[ebp+16]
	int 0x80
	pop ebp
	ret

运行结果截图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37414405/article/details/84329875