LD Linker Error

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
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

LD Linker Error

Post by ollie123 »

Hello, I am new to this forum, and I'm sorry if I have posted on the wrong board. If so, please tell me where else to post this.

I am new to OS development. I have just used gcc and nasm to create two .o files (one being kernel.o, and the other being main.o).
They both compile fine. However, when I come to use the LD Linker, I get an error:
kernel.o: file not recognized: File format not recognized
This is the command line I am using for LD:
ld -e _begin -Ttext 0x1000 -o first.bin kernel.o main.o
I would appreciate a response.
Cheers, ollie123.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

Obviously ld doesn't like your object file - could you please post:

* The command line that you use to create that file (the gcc compile line).
* The platform that you are compiling on (linux? cygwin?)
* The output of the command

Code: Select all

file kernel.o
Cheers,

James
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

For compiling the kernel.o file I am using:
nasm -f aout kernel.asm -o kernel.o
Then the main.o file:
gcc -c main.c -o main.o
And you already know the linker command line.

I am using MinGW.

Thanks for the help.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

Change your nasm line to

Code: Select all

nasm -f elf kernel.asm -o kernel.o
This should fix your problem.

Cheers,

James
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

Thanks a lot, it compiles perfectly now.
:D
Post Reply