is incompatible with i386:x86-64 output报错

在[一个操作系统的实现]书中,第五章,开始编译elf文件格式的操作系统内核。

将hello.asm编译为hello.o,再编译为可执行文件

编译hello.o时,nasm报错is incompatible with i386:x86-64 output。

原因是原实验是在32位操作系统下做的,使用的库也是32位的,而现在使用的64位操作系统。

 

解决方法:

修改上述两步编译的写法:

nasm -f elf64 -g -F stabs sandbox.asm -o sandbox.o
ld -o sandbox sandbox.o

也可以生成兼容32位的应用程序,再编译为可执行文件:

nasm -f elf -g -F stabs sandbox.asm -o sandbox.o
ld -m elf_i386 -o sandbox sandbox.o

 

 

顺便,gcc编译也会出现类似问题

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

出现这种警告的时候的时候,运行程序老是段错误,要加-ms32,就好了。

gcc -m32 -o usehello_static usehello.c libhello.a

转载于:https://www.cnblogs.com/zx1116/p/7810069.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值