Linking with LD

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.
Post Reply
PlayOS

Linking with LD

Post 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.
Tim

Re:Linking with LD

Post by Tim »

You've got -oformat binary (one hyphen). It should by --oformat binary (two hyphens).
PlayOS

Re:Linking with LD

Post by PlayOS »

When I use two hyphens I get the error saying something about operating on PE files?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Linking with LD

Post 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 ?
PlayOS

Re:Linking with LD

Post by PlayOS »

Any ideas on how I should compile and link my C Source to get it to work?
Tim

Re:Linking with LD

Post 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]
PlayOS

Re:Linking with LD

Post by PlayOS »

OK, I'll give it a go. Thanks.
PlayOS

Re:Linking with LD

Post by PlayOS »

Thanks Tim, it worked perfectly. Thanks Heaps.
Post Reply