ld: i386 架构于输入文件foo.o 与 i386:x86-64 输出不兼容

在编译链接过程中遇到'ld: i386 architecture of input file `foo.o' is incompatible with i386:x86-64 output'的错误,原因是32位nasm目标代码与64位gcc代码冲突。解决方案包括让gcc生成32位代码并以32位方式链接,或者安装32位库以支持32位程序构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错:ld: i386 架构于输入文件 foo.o 与 i386:x86-64 输出不兼容

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

编译链接指令

nasm -f elf foo.s -o foo.o

gcc -c bar.c -o bar.o

ld -s -o foobar bar.o foo.o

汇编语言用nasm编写并用nasm编译器编译,而C语言用的是gcc编译,这些都没有问题,但是在链接的时候出错了,提示如下:
ld: i386 architecture of input file `foo.o' is incompatible with i386:x86-64 output


意思就是nasm 编译产生的是32位的目标代码,gcc 在64位平台上默认

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值