Page 1 of 1

[SOLVED] Tutorial won't compile

Posted: Thu Apr 22, 2010 3:56 pm
by MTK358
I was trying to compile the "Bare Bones" tutorial from the Wiki and I can't get it to compile. My desktop is 64-bit Arch Linux.

Anyway, this is what happens:

Code: Select all

$ nasm -f elf32 -o loader.o loader.s
$ gcc -o kernel.o -c kernel.c -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32
kernel.c: In function ‘kernel_main’:
kernel.c:1: warning: unused parameter ‘mbd’
$ ld -T linker.ld -o kernel.bin loader.o kernel.o
ld: i386 architecture of input file `loader.o' is incompatible with i386:x86-64 output
ld: i386 architecture of input file `kernel.o' is incompatible with i386:x86-64 output
It looks like ld is trying to produce a 64-bit executable. What should I do?

Re: Tutorial won't compile

Posted: Thu Apr 22, 2010 4:00 pm
by NickJohnson
Two words: cross compiler. Try the wiki.

Re: Tutorial won't compile

Posted: Thu Apr 22, 2010 4:26 pm
by Combuster
Your tutorial wrote:you are strongly encouraged to set up a GCC Cross-Compiler, as it removes all the various toolchain-specific issues you might have
Really, was repeating this necessary? :roll:

Re: Tutorial won't compile

Posted: Thu Apr 22, 2010 6:07 pm
by -m32
You just need to tell the linker to output a 32 bit object. You don't need a cross compiler to do that.

Just add -melf_i386 to your call to ld, or tell your linker script to use a 32 bit target.

Re: Tutorial won't compile

Posted: Thu Apr 22, 2010 6:40 pm
by MTK358
-m32 wrote:You just need to tell the linker to output a 32 bit object. You don't need a cross compiler to do that.

Just add -melf_i386 to your call to ld, or tell your linker script to use a 32 bit target.
That works! Thanks!

Re: [SOLVED] Tutorial won't compile

Posted: Fri Apr 23, 2010 1:11 am
by Solar
Why do we even bother to write FAQ's, tutorials and the whole shebang when every time a question should best be answered with nothing more than a Wiki link gets a customized answer by someone anyway?

The result: Same user, next question, and again about something that's in plain view in the relevant tutorial.

Get me right, I am not attacking the OP here. But this is an education thing: do we want to teach people to look through the Wiki first (because most questions are answered by Wiki links anyway), or do we teach them to ask first, read later? Because they get nice cosy custom solutions spoon-fed to them?