Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
5.00/5 (3 votes)
Hi there,

I am a beginner and I have a question. Why is it that an executable file that works in one OS will not work in another OS (even if we don't use any system API)?

Thank you.
Posted
Updated 19-Jan-11 4:07am
v2
Comments
Sergey Alexandrovich Kryukov 19-Jan-11 9:50am    
Good question
pasztorpisti 19-Jan-11 9:56am    
I have never been thinking about this particular problem...

Different api's and different executable file formats.

Your applications is allways using an os api - but often indirectly through runtime libraries.

On linux you will find:Executable and Linkable Format[^]

While Windows uses:Portable Executable[^]

Consider using java or .Net - that way your applications may be able to execute on different os'es.

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Nish Nishant 19-Jan-11 9:56am    
Good answer. 5!
Espen Harlinn 19-Jan-11 9:58am    
Thank you!
Sergey Alexandrovich Kryukov 19-Jan-11 10:14am    
Good answer, my 5. I though more general and less concrete overview would be adequate though.
Espen Harlinn 19-Jan-11 14:27pm    
Thanks SAKryukov
HimanshuJoshi 19-Jan-11 20:17pm    
+5.
Assuming your app does not use any OS specific API, which means it does not have any means of input or output, and all it does is use plain x86 or x64 instructions for moving data around registers, then theoretically the same binary code will execute on multiple OSes. The problem them comes with the loading of the executable. Different OSes have different mechanisms for process management and creating/executing processes.

If you want binary portability, then use platforms like Java or Mono where they have VM layers on top of the OS which will abstract away the underlying OS. Now the same binary (byte code, IL, whatever) will execute on multiple OSes provided you don't need to interop into the native OS API.
 
Share this answer
 
Comments
Espen Harlinn 19-Jan-11 10:00am    
5+ good point about the instruction set - elf binaries exits for a wide range of harware platforms.
Sergey Alexandrovich Kryukov 19-Jan-11 10:14am    
Good answer, my 5. I though more general and less concrete overview would be adequate though.
HimanshuJoshi 19-Jan-11 20:17pm    
+5 Nice answer.
Nish Nishant 19-Jan-11 20:18pm    
Thanks.
Short answer is: by historical reasons.

Naturally, if the systems have different CPU, in traditional paradigm the executable code is composed of machine-code instruction, but even with identical CPU's the executables are usually incompatible. Different classes of OS use very different approaches, different file formats.

Programming platforms based on intermediate byte code are different. For example, I run my .NET programs (if they are written using some standard sub-set of API (in practice, well beyond)) on Windows and Linux. Executable files are built into intermediate code (CIL) and compiled in machine code on every target machine during execution using mechanism called Just-In-Time compilation (JIT). See http://en.wikipedia.org/wiki/.NET_Framework[^], http://en.wikipedia.org/wiki/Just-in-time_compilation[^].

Java machine also makes compiled Java code platform-independent: http://en.wikipedia.org/wiki/Just-in-time_compilation[^].

There are other platforms based on similar approaches, mostly historical. It's hard to say if platform-independent technologies are taking over or not, but they certainly grow quite aggressively.

By the way, you should not assume you don't use API. Eventually you do. How do you do input/output? Even with file system of console, this is done through OS API. Theoretically speaking, a DLL (or Shared Library) could present purely data and calculations, without any API calls, but in real life this is unlikely. Even in this case, DLL's executable files are incompatible.
 
Share this answer
 
v2
Comments
Nish Nishant 19-Jan-11 10:17am    
I think this answer is different enough from the other 2 answers and adds to the discussion content. Voted 5 for that.
Espen Harlinn 19-Jan-11 10:19am    
5+ a good community effort
pasztorpisti 19-Jan-11 10:27am    
Mentioning different architectures is a good point, especially if an OS like Linux is multiplatform...
Sergey Alexandrovich Kryukov 19-Jan-11 10:32am    
Thank you very much guys.
HimanshuJoshi 19-Jan-11 20:18pm    
+5 for thorough and general answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900