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
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

File format not recognized

Post by CodeVisio »

Hi All,

I'm following this tutorial http://www.osdever.net/bkerndev/Docs/title.htm, but I'm not able to link.
At the end ld says, "File format not recognized" and it is referring to the assembler file included in that tutorial.

As tools I'm using MinGW (mingw.org) and nasm, both recently downloaded.
I'm not using DJGPP because I have a 64 bit Windows, 7.

Any suggestion?

Thank you.
Last edited by CodeVisio on Sat Aug 25, 2012 2:19 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

By default nasm produces bin format files. You are specifying "-f elf" on the command line, I presume?
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

By default nasm produces bin format files. You are specifying "-f elf" on the command line, I presume?
No, I'm following exactly what the tutorial says, that is:
From build.bat file:
nasm -f aout -o start.o start.asm.

Thank you.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

A modern version of ld will almost certainly be expecting elf format input files by default. If you want to use an alternative format then you have to tell it so. The easiest solution is just to use elf format all round.

You need to understand your toolset; don't follow tutorials blindly. But these mistakes are good as they help us better understand what we are doing.
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

A modern version of ld will almost certainly be expecting elf format input files by default. If you want to use an alternative format then you have to tell it so. The easiest solution is just to use elf format all round.
Before posting here I've tried different nasm object file format output and ld claims with different errors.
I've tried nasm with aout, bin, elf, elf32, elf64, coff, win32, win64 ecc but without success.
My first guess was that ld, and so MinGW, was targeted, as release, for 32 bit Windows, but I'm not quite sure.
You need to understand your toolset; don't follow tutorials blindly. But these mistakes are good as they help us better understand what we are doing.
I agree.

Any suggestion?

Thank you.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

Build a cross-compiler as you are not compiling Windows programs: http://www.mingw.org/wiki/HostedCrossCompilerHOWTO .

Alternatively, install Linux in a VM and use that for OS development. In the end I found Windows too much of a pain as a development environment.
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

Build a cross-compiler as you are not compiling Windows programs: http://www.mingw.org/wiki/HostedCrossCompilerHOWTO .
I've read the info on that page...:) I dont' know if I have the strength to do so.
Alternatively, install Linux in a VM and use that for OS development. In the end I found Windows too much of a pain as a development environment.
Indeed I was able to compile and link all those files from the tutorial on a linux pc, but since I have all my dev stuff here, on the Windows pc, I didn't want to switch PCs.

I'll try it and provide feedback here.

Thank you
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: File format not recognized

Post by Combuster »

I dont' know if I have the strength to do so.
How long do you plan on getting stuck with this? :wink:
"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 ]
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

I dont' know if I have the strength to do so.
Building a cross-compiler is pretty much essential for OS development and is one of the easier tasks (especially with step-by-step instructions). It doesn't bode well for any further ambitions you may have.
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

I've just gave a look at the mingw web page mentioned above about cross platform and:
The tools the web page talks about are not updated, as mentioned at top of the page itself.
I give up since I don't know how much time it would take and I don't like spending time and just discovering at the end
that the tools are not the right ones or are not long compatible etc etc.
So I'll continue on linux pc.

One more thing:
When I installed MinGW distribution I believed the tools coming with MingW were much the same as the counterpart you find on linux.
Let's take gcc for example: gcc is ported o Windows platform so I can run it from the cmd.exe command line, at the same time I believed that
the entire porting was related only on the platform it needs to run on and not related to its features. In other word I believed I can run gcc with same parameters and get the same result on linux as on Windows. Am I wrong?

Thank you.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

If it works on Linux but not on Windows then obviously the toolsets are not the same. I don't really know anything about mingw but I guess it's configured to create Windows excecutables.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: File format not recognized

Post by Tosi »

MinGW is a port of basic GNU utilities, mainly the GNU Compiler Collection (GCC) and binutils (as, ld, objcopy, objdump, nm, ar, ...) to Windows, as an alternative to Microsoft's development tools. It is only meant to be used to create Windows PE executables, but uses ELF as an intermediate format when creating object files. If you wish to do OS development, either make a flat binary kernel, use a PE format kernel (which is harder to read than ELF), or build a cross-compiler. If you can't do one of those, then you are not ready for OS development.
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

Hi Tosi!
MinGW is a port of basic GNU utilities, mainly the GNU Compiler Collection (GCC) and binutils (as, ld, objcopy, objdump, nm, ar, ...) to Windows, as an alternative to Microsoft's development tools. It is only meant to be used to create Windows PE executables, but uses ELF as an intermediate format when creating object files.
This is the point where I came at the end of my inspection.
Question: do you think it's possible to develop an OS with VC compiler + tasm (or nasm)? (otherwise how could Microsft ever developed its own...)
If you wish to do OS development, either make a flat binary kernel, use a PE format kernel (which is harder to read than ELF), or build a cross-compiler.
I've tried with -f win32 and -f win64 option from nasm but it didn't work.
If you can't do one of those, then you are not ready for OS development.
I don't think it is feasible for someone only to make a complete OS, from technical, time, and commercial point of views.
However, I'm interested in this:
What is the logical and practical implication between "build a cross compiler" and "you are not ready for OS development"?

Thank you for your information
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: File format not recognized

Post by iansjack »

What is the logical and practical implication between "build a cross compiler" and "you are not ready for OS development"?
As it's a suggestion that I also made, I'll add my take on this.

Look upon it as a sort of test (as well as providing a useful utility). Building a cross-compiler is orders of magnitude simpler than writing an OS. If you find the former too difficult then you will only find the latter frustrating.
CodeVisio
Posts: 13
Joined: Sat Aug 25, 2012 1:59 am

Re: File format not recognized

Post by CodeVisio »

I think I got it and I agree totally.
Post Reply