Ld error? File format not recognized

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
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Ld error? File format not recognized

Post by samoz »

Hello all, I'm having some problems. I'm following James Molloy's tutorial and it's worked fine up to this point.

I'm at the 3rd part of the tutorial where it's talking about writing to the screen. I typed it all in and hit make, but I get the following error:

boot.o: file not recognized: File format not recognized

To make sure it wasn't a typo, I extracted the source from the tar available on the website, and still the same thing.

Why would this be happening?

I'm on windows by the way.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

What compiler are you using?
Its obviously outputting in a format LD doesn't recognize.
You might need a cross compiler.
Jules
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Ld error? File format not recognized

Post by JamesM »

samoz wrote:Hello all, I'm having some problems. I'm following James Molloy's tutorial and it's worked fine up to this point.

I'm at the 3rd part of the tutorial where it's talking about writing to the screen. I typed it all in and hit make, but I get the following error:

boot.o: file not recognized: File format not recognized

To make sure it wasn't a typo, I extracted the source from the tar available on the website, and still the same thing.

Why would this be happening?

I'm on windows by the way.
make sure you "make clean" before you "make". I accidentally tarred up some object files in the downloads I put on my site, and they of course will only work properly in my build environment. "make clean" will remove all those .o's and force "make" to build them from scratch again.

If that's not the problem then I assume that the cygwin toolchain doesn't support ELF properly, but that's for someone more used to cygwin than me to work out.
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Post by samoz »

I'm using DJGPP's gcc. gcc -v shows that it is 4.2.3

I did make clean, and the same issue arose...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

samoz wrote:I'm using DJGPP's gcc. gcc -v shows that it is 4.2.3

I did make clean, and the same issue arose...
execute the command "file boot.o" and paste what it returns.
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Post by samoz »

boot.o: ELF 32-bit LSB relocatable 80386 Version 1
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

ld shouldn't have any problem linking it then...
(I think...)
Jules

edit; sorry I didn't catch on to the fact that you were using a UNIX like plaform...
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

samoz wrote:boot.o: ELF 32-bit LSB relocatable 80386 Version 1
Hmm. interesting. I'll leave it to some cygwin users to identify the problem. It is cygwin you're using, isn't it? because otherwise your LD won't be configured to output ELF binaries.
User avatar
ollie123
Member
Member
Posts: 26
Joined: Tue May 27, 2008 2:42 am
Location: Great Yarmouth, Norfolk, United Kingdom

Post by ollie123 »

Is it assembly code? Are you using NASM? If you are, make sure your command line is

Code: Select all

nasm -f elf -o boot.o [your asm file here]
NEW TO OPERATING SYSTEM DEVELOPMENT
Good OS Development Tutorials: http://www.brokenthorn.com/Resources/OSDevIndex.html
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Is it assembly code? Are you using NASM? If you are, make sure your command line is
There's nothing wrong with the NASM command line, as you can see an ELF object is being output;
samoz wrote:boot.o: ELF 32-bit LSB relocatable 80386 Version 1
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post by Zenith »

IIRC, the Cygwin/Mingw LDs don't properly support ELF executables if you don't cross-compile them.
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Post by samoz »

Do you mean cross compile them on UNIX and transfer them to Windows or cross-compile for Windows to UNIX?
MELLOMAN5123
Posts: 1
Joined: Wed Dec 22, 2010 3:58 pm

Re: Ld error? File format not recognized

Post by MELLOMAN5123 »

try this
nasm -f coff -o boot.o
Last edited by MELLOMAN5123 on Sun Mar 13, 2011 9:36 pm, edited 1 time in total.
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: Ld error? File format not recognized

Post by Combuster »

Hmm, necroposting, doing so with a broken answer, and then asking to reply by mail.

None of the three is good etiquette :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 ]
Post Reply