[SOLVED] Tutorial won't compile

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Locked
MTK358
Posts: 5
Joined: Thu Apr 22, 2010 2:52 pm

[SOLVED] Tutorial won't compile

Post 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?
Last edited by MTK358 on Thu Apr 22, 2010 6:48 pm, edited 1 time in total.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Tutorial won't compile

Post by NickJohnson »

Two words: cross compiler. Try the wiki.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Tutorial won't compile

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
-m32
Member
Member
Posts: 120
Joined: Thu Feb 21, 2008 5:59 am
Location: Ottawa, Canada

Re: Tutorial won't compile

Post 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.
MTK358
Posts: 5
Joined: Thu Apr 22, 2010 2:52 pm

Re: Tutorial won't compile

Post 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!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: [SOLVED] Tutorial won't compile

Post 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?
Every good solution is obvious once you've found it.
Locked