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

LinuxLdI386

Linux Problem Overview


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

Linux Solutions


Solution 1 - Linux

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

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

Solution 2 - Linux

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 - Linux

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

Solution 4 - Linux

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMEv2.0View Question on Stackoverflow
Solution 1 - LinuxLeandro AndradeView Answer on Stackoverflow
Solution 2 - LinuxDrillView Answer on Stackoverflow
Solution 3 - Linux4aRk Kn1gh7View Answer on Stackoverflow
Solution 4 - LinuxShanu VermaView Answer on Stackoverflow