编译命令:
nasm -f elf hello.asm -o hello.o
ld -s hello.o -o hello
报错信息:
ld: i386 architecture of input file `hello.o' is incompatible with i386:x86-64 output
解决方法:
命令行输入:>ld -m elf
ld: unrecognised emulation mode: elf
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om elf_k1om i386pep i386pe
根据输出选择对应的架构选项,将链接命令修改为:ld -m elf_i386 -s -o hello hello.o
如果需要链接gcc编的.o文件,则gcc编译命令需要加上-m32参数,如:gcc -m32 -c -o bar.o bar.c
详见:
http://www.linuxquestions.org/questions/programming-9/assembly-error-i386-architecture-incompatible-with-i386-x86-64-output-827609/
http://www.ithao123.cn/content-5258444.html