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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM