Executable files

This question always confuses me :-

Suppose I write a program and compile it on a machine with operating system A and processor B

will the exe file run on a machine

with operating system A2 but processor B
operating system A but processor B2
operating system A2 and processor B2........

In a nutshell, Does the compatibility of a exe file depend on

only operating system ?

only machine architecture ?

or BOTH ?

There are CPUs: i386, Sparc, PowerPC, MIPS, PA-RISC, MC68020 etc

There are object file formats: ELF, XCOFF, COFF, PE, SOM, AOUT etc

Then there are CPU modes, 64 bit, 32 bit

And also operating system versions, so typically a binary compiled for one version of an OS cannot be used on an earlier one.

Hi.

And there is Executable - Wikipedia, the free encyclopedia ... cheers, drl

Porter

Some body told me like this:

"I think it totally depends upon the OS, provided it abstracts hardware efficiently. For example, Windows is meant for x86 architechture. Someday Microsoft comes up with Windows for SPARC that uses same system calls, i.e. H/W is abstracted. Any Win32 program would run on that too.

Virtual Machines (such as JVM) do exactly that. They provide a consistent set of instructions to the programs accross platforms. Underneath these instructions are executed differently on different systems."

What you say now?

some body told you correctly

And also previously ran on MIPS, DEC-Alpha and PowerPC.

Except that any code compiled for i386 will have to be run through an emulator.

Absolutely, (a) at the cost of translation to the native format (b) JVM and .NET both still sit on top of an operating system, they do not replace it.

Even a JVM running in a embedded system will still run on an embedded OS, however minimalist that is.

What is meant by native format????

I'll add one more question, A file compiled on x86-32 architecture under Windows XP, will it work on x86-64 architecture under Windows XP or Windows 2003?

Can I get a link where some guide is provided how OS and hardware architecture interact with each other. I'm really confused, not exactly understanding what is happening (inside the hardware, OS and system calls).

Thanks for all your support.

Native implies it is compatible with the CPU in the machine and complies with the default ABI (Application Binary Interface) of the operating system.

Upto a point, it will be compiled to the WIN32 standard. Code can be compiled for Win32 and work without change from Windows 3.1 running WIN32S through to Windows Vista, as long as the calls it makes are implemented on that platform. Overtime APIs are added to a platform, if you restrict the set you call you can maintain good backward compatibility.

Note, the a x86-64 processor can run both 32bit and 64bit binary code. But a 386 cannot run 64 bit code natively.

Similarly an UltraSparcII can run both 32bit and 64bit SPARC code, but a DEC-Alpha is only available as 64bit, there is no 32bit equivalent.

So you mean a code compiled under Windows XP(64-bit) will not work in Windows XP(32-bit)?

Almost.

Code compiled for WIN64 will not run on any WIN32 platform.

You can still compile WIN32 code on a WIN64 platform.