Architecture of i386 input file is incompatible with i386:x86-64

后端 未结 4 645
不思量自难忘°
不思量自难忘° 2020-12-22 22:42

I\'m trying to create a simple kernel using Ubuntu. In the terminal I typed

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

But I got

相关标签:
4条回答
  • 2020-12-22 23:20

    I also faced the same problem, i figured out that i am 32 bit registers(eax,ecx,edx,ebx,esp,ebp,esi,edi) insist of 64 bit registers (rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi), in my 64 bit computer. Then use these command to compile my program-

    nasm -felf64 hello.asm
    ld hello.o
    ./a.out
    
    0 讨论(0)
  • 2020-12-22 23:21

    Use 64 bits instead of 32 for your loader and compile it with the following command:

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

    This should solve your error

    0 讨论(0)
  • 2020-12-22 23:24

    If want compile the file as 32 bits, you can use:

    ld -m elf_i386 -s -o file file.o
    
    0 讨论(0)
  • 2020-12-22 23:28

    When compiling/linking 32-bit apps on x86_64, setting emulation to elf_i386 provides the correct elf format. So, for example, if you compile an assembler app with nasm -f elf file.asm -o file.o, the link command is ld -m elf_i386 -o exename file.o Courtesy: David

    0 讨论(0)
提交回复
热议问题