always chase after what I like, but never forget what I dream of."

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

posted @ 2017-11-09 16:28  zx1116  阅读(6048)  评论(0编辑  收藏  举报

always chase after what I like, but never forget what I dream of."