2013-10-05 77 views
15

我試圖用Ubuntu創建一個簡單的內核。在終端我鍵入i386輸入文件的體系結構與i386不兼容:x86-64

ld -Ttext 0x1000 -o kernel.bin loader.o main.o Video.o 

但我得到的回報以下錯誤信息:

ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output 
    ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000 

回答

20

使用64位而不是32爲您的裝載機和使用以下命令編譯:

nasm -f elf64 loader.asm -o loader.o 

這應該解決你的錯誤

22

如果想編譯文件爲32位的組合物,可以使用:

LD -m elf_i386 -s -o file.o文件

+4

這是解決方案。在x86_64上編譯/鏈接32位應用程序時,將仿真設置爲'elf_i386'提供了正確的elf格式。因此,例如,如果使用'nasm -f elf file.asm -o file.o'編譯彙編程序,鏈接命令是'ld -m elf_i386 -o exename file.o'。 –

+1

只要不忘記用'-o file file.o'替換'-o file.o文件'。 – Ruslan

2

當編譯/在x86_64聯的32位應用程序,設置仿真到elf_i386提供正確的elf格式。因此,例如,如果您使用nasm -f elf file.asm -o file.o編譯彙編程序,則鏈接命令爲ld -m elf_i386 -o exename file.o 禮貌:David

相關問題