Page 1 of 1
File format not recognized
Posted: Sat Aug 25, 2012 2:05 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 2:14 am
by iansjack
By default nasm produces bin format files. You are specifying "-f elf" on the command line, I presume?
Re: File format not recognized
Posted: Sat Aug 25, 2012 2:17 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 2:38 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 3:01 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 3:17 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 3:30 am
by CodeVisio
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
Re: File format not recognized
Posted: Sat Aug 25, 2012 4:55 am
by Combuster
I dont' know if I have the strength to do so.
How long do you plan on getting stuck with this?
Re: File format not recognized
Posted: Sat Aug 25, 2012 5:03 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 8:42 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 9:08 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 10:13 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 10:35 am
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
Re: File format not recognized
Posted: Sat Aug 25, 2012 10:39 am
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.
Re: File format not recognized
Posted: Sat Aug 25, 2012 10:46 am
by CodeVisio
I think I got it and I agree totally.