I was following the osdev barebones tutorial and made a custom Makefile to it, but when I ran make kernel
to compile the system into a .bin file, I ran into an error while linking.
Linker output:src/kernel.o: file not recognized: file format not recognized
Linker command:$HOME/opt/cross/bin/i686-elf-gcc -T linker.ld -o kernel.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
I took a quick look into it, and I found out that i686-elf-gcc cross-compiler produced a 64-bit file. Weird. I tried compiling kernel.c with the same flags, and it worked just fine. What could the problem be?
CPARAMS:
-std=gnu99 -ffreestanding -O2 -Wall -Wextra
MAKEFILE: $(GCC) $(CPARAMS) -c $@ -o $<
So the actual command looks like this $HOME/opt/cross/bin/i686-elf-gcc -std=gnu99 -ffreestanding -O2 -Wall -Wextra -c kernel.c -o kernel.o
File produced by running compiler via make:
kernel.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
File produced by running compiler from shell:
kernel.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped