Skip to content Skip to main navigation Skip to footer

Ubuntu 系统下NASM编译出错问题的解决方法

本文主要讲述如何在ubuntu 16.04/14.04系统下解决使用NASM编译文件时出现的问题(ld:i386 架构于输入文件与i386:x86-64输出不兼容)的解决方法。
1# 先查看当前ubuntu系统的cpu架构

$ uname -a
Linux ubuntutest 4.11.0-14-generic #20~16.04.1-Ubuntu SMP Wed Aug 9 09:06:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

从上面的输出可以看到,cpu是x86 64位
2# elf参数使用el64,执行下面的nasm编译命令

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

3# 如果要兼容编译32位模式,可以使用下面的nasm命令:

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