Page 1 of 1

Linking with LD

Posted: Sun Sep 29, 2002 11:17 pm
by PlayOS
Hi,

I have created a simple kernel in C, it just prints an 'A' to the screen and then hangs. The problem is that LD will not link it. I have tried

ld -Ttext 0x20000 -oformat binary -o kernel.bin kernel.o

and

ld kernel.o -o kernel.bin -oformat binary -Ttext 0x20000

both of these were given to me and none of them will work, I get an error saying 'cannot open binary: No such file or directory'

Any ideas?

Thanks.

Re:Linking with LD

Posted: Mon Sep 30, 2002 6:03 am
by Tim
You've got -oformat binary (one hyphen). It should by --oformat binary (two hyphens).

Re:Linking with LD

Posted: Mon Sep 30, 2002 6:06 am
by PlayOS
When I use two hyphens I get the error saying something about operating on PE files?

Re:Linking with LD

Posted: Mon Sep 30, 2002 6:11 am
by Pype.Clicker
isn't this that well-known problem about LD that isn't able to output flat binary from a COFF/PE output ?

Re:Linking with LD

Posted: Mon Sep 30, 2002 6:15 am
by PlayOS
Any ideas on how I should compile and link my C Source to get it to work?

Re:Linking with LD

Posted: Mon Sep 30, 2002 7:42 am
by Tim
Compile to PE as normal (i.e. don't use --oformat binary). Use objcopy to convert from PE to binary:
[tt]objcopy -O binary kernel.exe kernel.bin[/tt]

Re:Linking with LD

Posted: Mon Sep 30, 2002 11:48 am
by PlayOS
OK, I'll give it a go. Thanks.

Re:Linking with LD

Posted: Mon Sep 30, 2002 9:19 pm
by PlayOS
Thanks Tim, it worked perfectly. Thanks Heaps.