Having some trouble 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
Glitch

Having some trouble with 'ld'

Post by Glitch »

*Ignore this if you don't wanna read it, its just some background info*
Ok, for my science fair project(due in 2 days) I have chosen to write a very simple OS and run a small PI calculation on it and compare the speeds to Window$ and Linux...  So all I really want to do is have a simple 'boot off disk' little OS.  I found a tutorial and I also bought the book 'Operating System Design and Implementation' by Andrew S. Tenenbaum(he wrote minix)..  I know java like the back of my hand but that doesnt really help me here.  I have enough knowledge in C amd C++ to do basic stuff like input and output and such.  I can write the rest of it myself(Except fot timing things, have no clue how to get current system time).  
*end possible ignore*


So heres my problem...  The tutorial is a little outdated and I get an error when using ld like the tutorial says.  Heres the part of the tutorial that tells me to do this(Taken from planetsourcecode.com):

"Now, lets compile this code.
Compile the ASM code like this:
NASM -f coff kernel.asm
That should create an output file called kernel.o

Compile our C code like this:
gcc -O3 -c kernel_c.c
That will output a kernel_c.o

Link the 2 files like this:
ld -Ttext 0xFF800000 --oformat binary -o kernel.bin kernel.o kernel_c.o
You should get a warning that says it cant find the entry symbol start. This is what you want ;)
Linking those produces a flat binary called kernel.bin
This is your operating system. "


Now the problem is with the ld command(ld -Ttext 0xFF800000 --oformat binary -o kernel.bin kernel.o kernel_c.o)  I don't remember the error exactly(if you need me to I can go check it) but it said something like 'kernel.o is unknown format'  Thank you soo much for all your help..  Oh yeah and if you wanna check out the tutorial, it's at http://www.planet-source-code.com/vb/sc ... 3&lngWId=3

Thank you for your time,
Chris
Dangamoose

RE:Having some trouble with 'ld'

Post by Dangamoose »

Are you using Windows to compile?.

If your using Windows to compile then it could be that ld does not support coff files. I know it doesnt support elf files when built for windows.

You'll either need to compile on a linux box where ld supports coff, or recompile ld for linux to support coff, or just use a file format that your ld build understands.

Dangamoose
Glitch

RE:Having some trouble with 'ld'

Post by Glitch »

Well, I tried compiling the asm in binary format and it gives me an error that the asm program cannot make external references.  Here's a copy of the asm program:  



[bits 32] ;Make our OS 32bit

SECTION .text

EXTERN _c_main ;Reference to our main function in the c code.
;Note that our function in C starts with an underscore (_)
;This is because when we compile our C file, functions are started with
;underscores. THis is not so for ASM files though.

start:
call _c_main ;This calls our main function in the C file
jmp $ ;Freezes the computer because theres nowhere else to go!



and yes i just tried using cygwin on windows and i get a different error: "PE operations on non PE file"

My project is due tommarrow!!  i have to finish tonight!!

thanks, Glitch
Glitch

RE:Having some trouble with 'ld'

Post by Glitch »

Oh and by the way i have a dual boot and the original post was when i was trying to compile in linux..
Glitch

RE:Having some trouble with 'ld'

Post by Glitch »

ok, i now figured out what to do, but i am still getting the error.  I am using the Dev C++ version of GCC for windows, and i get "PE operations on non PE file" error.  how can i fix this?
Post Reply