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

75,068

Solution 1

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

ld -m elf_i386 -s -o file file.o

Solution 2

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

Solution 3

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

Share:
75,068
MEv2.0
Author by

MEv2.0

Updated on July 13, 2022

Comments

  • MEv2.0
    MEv2.0 5 months

    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 the following error message in return:

    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
    
  • David C. Rankin
    David C. Rankin over 8 years
    This was the solution. 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.
  • Ruslan
    Ruslan over 6 years
    Just don't forget to replace -o file.o file with -o file file.o.
  • fcdt
    fcdt over 2 years
    The 32 bit registers still exists in 64 bit mode, but you cannot just compile a 32 bit assembly programm to 64 bit without rewriting it. Porting to 64 bit can also make it necessary to adjust the size of data structures, as pointers become twice as large.
  • Admin
    Admin over 2 years
    Exactly , you are right .But when we want to write code 0x86-64 (64 bit) assembly program, we have to use 64 bit registers.Basically faced the same problem and got the solution using these instruction .Correct if am wrong
  • Balázs Börcsök
    Balázs Börcsök over 1 year
    It would be great to set this as the solution if it works indeed.